The
FieldServer Modbus RTU drivers offer several function moves that handle
32-bit integers and 32-bit float values. More importantly, these
function moves consider all different forms of byte sequencing.
The following table shows the FieldServer function moves that copy two adjacent 16-bit registers to a 32-bit integer value.
Function Keyword |
Swap Mode |
Source Bytes |
Target Bytes |
2.i16-1.i32 |
N/A |
[ a b ] [ c d ] |
[ a b c d ] |
2.i16-1.i32-s |
byte and word swap |
[ a b ] [ c d ] |
[ d c b a ] |
2.i16-1.i32-sb |
byte swap |
[ a b ] [ c d ] |
[ b a d c ] |
2.i16-1.i32-sw |
word swap |
[ a b ] [ c d ] |
[ c d a b ] |
The
following table shows the FieldServer function moves that copy two
adjacent 16-bit registers to a 32-bit floating point value:
Function Keyword |
Swap Mode |
Source Bytes |
Target Bytes |
2.i16-1.ifloat |
N/A |
[ a b ] [ c d ] |
[ a b c d ] |
2.i16-1.ifloat-s |
byte and word swap |
[ a b ] [ c d ] |
[ d c b a ] |
2.i16-1.ifloat-sb |
byte swap |
[ a b ] [ c d ] |
[ b a d c ] |
2.i16-1.ifloat-sw |
word swap |
[ a b ] [ c d ] |
[ c d a b ] |
The
following table shows the FieldServer function moves that copy a single
32-bit floating point value to two adjacent 16-bit registers:
Function Keyword |
Swap Mode |
Source Bytes |
Target Bytes |
1.float-2.i16 |
N/A |
[ a b c d ] |
[ a b ][ c d ] |
1.float-2.i16-s |
byte and word |
[ a b c d ] |
[ d c ][ b a ] |
1.float-2.i16-sb |
byte swap |
[ a b c d ] |
[ b a ][ d c ] |
1.float-2.i16-sw |
word swap |
[ a b c d ] |
[ c d ][ a b ] |
Given
the vairous FieldServer function moves, the correct handling of 32-bit
data is dependent on choosing the proper one. Observe the following
behavior of these FieldServer function moves on the known
single-precision decimal float value of 123456.00:
16-bit Values |
Function Move |
Result |
Function Move |
Result |
0×2000 0x47F1 |
2.i16-1.float |
123456.00 |
1.float-2.i16 |
0×2000 0x47F1 |
0xF147 0×0020 |
2.i16-1.float-s |
123456.00 |
1.float-2.i16-s |
0xF147 0X0020 |
0×0020 0xF147 |
2.i16-1.float-sb |
123456.00 |
1.float-2.i16-sb |
0×0020 0xF147 |
0x47F1 0×2000 |
2.i16-1.float-sw |
123456.00 |
1.float-2.i16-sw |
0x47F1 0×2000 |
Notice
that different byte and word orderings require the use of the
appropriate FieldServer function move. Once the proper function move is
selected, the data can be converted in both directions.
Of
the many hex-to-floating point converters and calculators that are
available in the Internet, very few actually allow manipulation of the
byte and word orders. One such utility is located at www.61131.com/download.htm where both Linux and Windows versions of the utilities can be downloaded.
Once
installed, the utility is run as an executable with a single dialog
interface. The utility presents the decimal float value of 123456.00 as
follows:
One
can then swap bytes and/or words to analyze what potential endianness
issues may exist between Modbus RTU master and slave devices.