Quantcast
Channel: Chipkin Automation Systems » Modbus
Viewing all articles
Browse latest Browse all 9

Converting Modbus 16 bit numbers to 32 bit numbers

$
0
0

Often the Vendor documentation does not report the byte order in which registers are served or the order in which words must be combined to form 32 bit numbers. For this reason FieldServer provides 4 functions to convert Modbus 16 bit numbers to 32 bit numbers.

2.i16-1.i32

2.i16-1.i32-s

2.i16-1.i32-sw

2.i16-1.i32-sb

Each of these functions takes 2x 16 bits numbers to form a 32 bit number. Each processes the bytes in a different order.

Practical Tip: The easiest way to determine which function to use is to experiment. Look at the values in the FieldServer Data Arrays. If the values are obviously wrong try the other move functions. (Don’t forget that some numbers may be scaled so the number you see in the Data Array may 10x or 100x too big / small).

Example:

In the move below if

DA_B01_REG[21] == 1 and

DA_B01_REG[22] == 2

Then

DA_B01_INT32[21] == 131073

Explanation

1 + 65536* 2 = 131073

Or In Hexadecimal

0×0001 + 0×0002 * 0×10000 = 0×20001

Moves

Source_Data_Array ,Source_Offset ,Target_Data_Array ,Target_Offset ,Length ,Function

DA_B01_REG ,21 ,DA_B01_INT32 ,21 ,2 ,2.i16-1.i32

By the way, the length is 2 because the move must process two values from the source.

Example:

DA_B01_REG[21] == 1 and

DA_B01_REG[22] == 2

Function In Use Value found in DA_B01_INT32[21]
2.i16-1.i32 131073
2.i16-1.i32s 16777728
2.i16-1.i32-sw 65538
2.i16-1.i32-sb 33554688


Viewing all articles
Browse latest Browse all 9

Trending Articles