---
title: "Modbus data types"
description: "Modbus data types in TapHome scripts: registers and ranges of Int16, UInt32, Float, Int64, Double and String, big/little-endian and byte-swap variants."
url: "https://taphome.com/en/docs/script/modbus-data-types/"
language: en
lastmod: 2026-11-06
generator: hugo
ai:
  topics: ["modbus","modbus-data-types","byte-order","scripting-language"]
  questions: ["Which Modbus data types can I use in TapHome scripts?","How many registers does a Float or a 64-bit value take?","What do BigEndian, LittleEndian and ByteSwap mean for Modbus registers?","Which data type matches the byte order ABCD, CDAB, BADC or DCBA from a device manual?","How do I read a 64-bit Modbus register?","How do I read a text string from Modbus registers?","How is a decimal value rounded when written to an integer register?"]
---

# Modbus data types

Modbus data types in TapHome scripts — Int16, Uint16, Int32, UInt32, Float, Bool, String and the 64-bit Int64, UInt64 and Double — with big-endian, little-endian and byte-swap variants.

Last updated: 2026-11-06

The data type is the third argument of [MODBUSR](https://taphome.com/en/docs/script/modbus/#modbusr), [MODBUSW](https://taphome.com/en/docs/script/modbus/#modbusw) and [MODBUSWNE](https://taphome.com/en/docs/script/modbus/#modbuswne) and of [UNPACKVALUE and PACKVALUE](https://taphome.com/en/docs/script/binary-data/). It decides how many 16-bit registers a value takes and in which order its bytes are stored. Data type names are not case sensitive.

## Base data types

Each base data type takes a fixed number of 16-bit registers and gives the script a value of a fixed type.

| Type | Registers | Range | Value in the script |
|---|---|---|---|
| `Bool` | 1 | 0 = `FALSE`, anything else `TRUE` | `bool` |
| `Int16` | 1 | −32 768 … 32 767 | number |
| `Uint16` | 1 | 0 … 65 535 | number |
| `Int32` | 2 | −2 147 483 648 … 2 147 483 647 | number |
| `UInt32` | 2 | 0 … 4 294 967 295 | number |
| `Float` | 2 | IEEE 754 single precision | number |
| `Int64`, `UInt64` | 4 | 64-bit whole numbers | `int64`, `uint64` |
| `Double` | 4 | IEEE 754 double precision | number |
| `String` | 1 – 123 | 2 characters per register | string |

Many devices store a decimal value as a whole number with a fixed scale — divide it after reading, for example `MODBUSR(H, 20, Int16) / 10`. BCD-coded values are converted with [FROMBCD](https://taphome.com/en/docs/script/bit-operations/#frombcd).

## Byte order variants

Every type exists in a big-endian and a little-endian variant; the 32- and 64-bit types also in byte-swap variants.

```text
BigEndianInt16      LittleEndianInt16
BigEndianUint16     LittleEndianUint16
BigEndianInt32      LittleEndianInt32       BigEndianInt32ByteSwap      LittleEndianInt32ByteSwap
BigEndianUint32     LittleEndianUint32      BigEndianUint32ByteSwap     LittleEndianUint32ByteSwap
BigEndianFloat      LittleEndianFloat       BigEndianFloatByteSwap      LittleEndianFloatByteSwap
BigEndianInt64      LittleEndianInt64       BigEndianInt64ByteSwap      LittleEndianInt64ByteSwap
BigEndianUint64     LittleEndianUint64      BigEndianUint64ByteSwap     LittleEndianUint64ByteSwap
BigEndianDouble     LittleEndianDouble      BigEndianDoubleByteSwap     LittleEndianDoubleByteSwap
```

| Flag | Meaning for registers |
|---|---|
| `BigEndian` | The most significant register comes first. This is the default: `Int32` is `BigEndianInt32`. |
| `LittleEndian` | The register order is reversed (word swap). For a 16-bit type, which has one register, the two bytes inside it are swapped. |
| `ByteSwap` | The two bytes inside every register are swapped. |

Device manuals often write the byte order as letters: A is the most significant byte of the value, and the letters follow the order in which the device sends the bytes. Each order matches one data type:

| In the manual | 32-bit type | 64-bit type |
|---|---|---|
| ABCD (big-endian) | `BigEndianFloat` (same as `Float`) | `BigEndianDouble` (same as `Double`), ABCDEFGH |
| CDAB (word swap) | `LittleEndianFloat` | `LittleEndianDouble`, GHEFCDAB |
| BADC (byte swap) | `BigEndianFloatByteSwap` | `BigEndianDoubleByteSwap`, BADCFEHG |
| DCBA (little-endian) | `LittleEndianFloatByteSwap` | `LittleEndianDoubleByteSwap`, HGFEDCBA |

The same applies to the integer types, for example CDAB is `LittleEndianInt32` and DCBA is `LittleEndianUint32ByteSwap`.

**Remarks**

- Reads and writes apply all flags the same way, so writing a value and reading it back with the same type gives the same value. On cores older than 2026.1, `MODBUSW` and `MODBUSWNE` ignored `ByteSwap` for `Int32` and `UInt32`.
- When a value reads as nonsense, try the variants in the manual Modbus operations of the app, which switch the data type over the same registers.
- In a byte collection the flags mean byte order instead — see [Byte order in collections](https://taphome.com/en/docs/script/binary-data/#byte-order).

**Example**

```taphome
MODBUSR(H, 0x0100, LittleEndianFloat);
MODBUSR(A, 30, BigEndianUint32ByteSwap);
```

## 64-bit data types

`Int64`, `UInt64` and `Double` take four registers; `Int64` and `UInt64` are read as 64-bit whole numbers, exact over the whole range, because a `double` holds whole numbers exactly only up to 2^53.

**Remarks** — A 64-bit value keeps all 64 bits in the [bit functions](https://taphome.com/en/docs/script/bit-operations/), so bits 32 to 63 of an alarm word are reachable.

**Example — energy counter in Wh, shown in kWh**

```taphome
VAR energy := MODBUSR(H, 100, UInt64);
energy / 1000;
```

**Errors** — *Modbus data type 'X' not supported. Please update your core unit to be able to use this feature.* — when the script is saved for an older core.

**Available** — TapHome Next 2026.1.40665+.

## String

`String` reads text stored two characters per register, the high byte first; the number of registers is the fourth argument.

**Remarks**

- `MODBUSR` reads 0 to 123 registers; the text ends at the first zero byte. Each byte is one character.
- `String` can only be read. `MODBUSW` and `PACKVALUE` do not write it.

**Example**

```taphome
MODBUSR(H, 14, String, 4);
# Result: text of up to 8 characters, for example a serial number
```

## Writing values

`MODBUSW`, `MODBUSWNE` and `PACKVALUE` convert the value to the data type before writing.

- Integer types round to the nearest whole number; a value exactly halfway goes to the even number, so `2.5` is written as `2` and `3.5` as `4`.
- A value outside the range of `Int16`, `Uint16` or `Float` stops the script: *Overflow when writing X as UInt16.*
- `NaN` can be written only to `Float` and `Double`. To an integer type it stops the script: *RegisterValueToWrites: Can't write double.NaN to modbus register* (`MODBUSW`, `MODBUSWNE`) or *PACKVALUE: Can't write double.NaN to modbus register*.
- `Bool` writes 1 for any value other than 0. `TRUE` and `FALSE` can also be written to number types as 1 and 0.

**Example — set point with one decimal place**

```taphome
MODBUSW(H, 20, Int16, ROUND(Te * 10));
```

**See also** — [Modbus functions](https://taphome.com/en/docs/script/modbus/), [Modbus scripts and prefetch](https://taphome.com/en/docs/script/modbus-scripts/), [Binary data](https://taphome.com/en/docs/script/binary-data/).
