are read and manipulated with their own function codes, apart from the registers. Many modern
devices do not utilize coils at all.
When working with coils, the data logger requires Boolean variables. When reading coils, each
Boolean in an array will hold the state of one coil. A value of True will set the coil, a value of
False will unset the coil.
7.2.7.3 Data Types
Modbus does not restrict what data types may be contained within holding and input registers.
Equipment manufacturers need to indicate what binary data types they are using to store data.
Registers are 16-bit, so 32-bit data types use 2 registers each. Some devices combine more
registers together to support longer data types like strings. The
ModbusMaster()
instruction
has a
ModbusOption
parameter that supports several different data types.
When data types use more than 1 register per value, the register order within the data value is
important. Some devices will swap the high and low bytes between registers. You can
compensate for this by selecting the appropriate
ModbusOption
.
Byte order is also important when communicating data over Modbus. Big Endian byte order is
the reverse of Little Endian byte order. It may not always be apparent which a device uses. If you
receive garbled data, try reversing the byte order. Reversing byte order is done using the
MoveBytes()
instruction. There is an example in CRBasic help for reversing the bytes order of
a 32-bit variable.
After properly reading in a value from a Modbus device, you might have to convert the value to
proper engineering units. With integer data types, it is common to have the value transmitted in
hundredths or thousandths.
Unsigned 16-bit integer
The most basic data type used with Modbus is unsigned 16-bit integers. It is the original Modbus
data type with 1 register per value. On the data logger, declare your destination variable as type
Long. A Long is a 32-bit signed integer that contains the value received. Select the appropriate
ModbusOption
to avoid post-processing.
Signed 16-bit integer
Signed 16-bit integers use 1 register per value. On the data logger, declare your destination
variable as type Long. A Long is a 32-bit signed integer that contains the value received . Select
the appropriate
ModbusOption
to avoid post-processing.
7. Communications protocols
99