DataConverter class

Data type conversion utilities for Modbus registers.

Modbus registers are 16-bit (2 bytes), but often represent larger data types like 32-bit integers, floats, or strings. This class provides utilities for converting between register arrays and various data types.

Example:

// Read temperature as Float32
final bytes = await client.readHoldingRegistersBytes(1, 100, 2);
final temp = DataConverter.bytesToFloat32(bytes);

// Write setpoint as Float32
final setpoint = 25.5;
final data = DataConverter.float32ToBytes(setpoint);
await client.writeMultipleRegistersBytes(1, 200, 2, data);

Constructors

DataConverter()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

bytesToFloat32(Uint8List bytes, {ByteOrder byteOrder = ByteOrder.bigEndian}) double
Convert bytes to 32-bit float (Float32/Single).
bytesToFloat64(Uint8List bytes, {ByteOrder byteOrder = ByteOrder.bigEndian}) double
Convert bytes to 64-bit double (Float64/Double).
bytesToInt16(Uint8List bytes) Int16List
Convert bytes to signed 16-bit integers.
bytesToInt32(Uint8List bytes, {ByteOrder byteOrder = ByteOrder.bigEndian}) int
Convert bytes to signed 32-bit integer (Int32).
bytesToString(Uint8List bytes, {bool trimNull = true}) String
Convert bytes to ASCII string.
bytesToUint16(Uint8List bytes) Uint16List
Convert bytes to unsigned 16-bit integers.
bytesToUint32(Uint8List bytes, {ByteOrder byteOrder = ByteOrder.bigEndian}) int
Convert bytes to unsigned 32-bit integer (UInt32).
float32ToBytes(double value, {ByteOrder byteOrder = ByteOrder.bigEndian}) Uint8List
Convert 32-bit float to bytes.
float64ToBytes(double value, {ByteOrder byteOrder = ByteOrder.bigEndian}) Uint8List
Convert 64-bit double to bytes.
getBit(Uint8List bytes, int bitIndex) bool
Get specific bit from byte array.
int16ToBytes(List<int> values) Uint8List
Convert signed 16-bit integers to bytes.
int32ToBytes(int value, {ByteOrder byteOrder = ByteOrder.bigEndian}) Uint8List
Convert signed 32-bit integer to bytes.
setBit(Uint8List bytes, int bitIndex, bool value) → void
Set specific bit in byte array.
stringToBytes(String value, {int? length}) Uint8List
Convert string to bytes.
uint16ToBytes(List<int> values) Uint8List
Convert unsigned 16-bit integers to bytes.
uint32ToBytes(int value, {ByteOrder byteOrder = ByteOrder.bigEndian}) Uint8List
Convert unsigned 32-bit integer to bytes.