Common issues faced by Modbus driver: Scrambled bytes and words

Question:

With Modbus driver, certain operations (especially when reading FLOAT-type variables) can take place, but the values are not sorted out in the order they were expected; that is, bytes and words are displayed in a scrambled order. How can I fix this?

Solution:

When reading values that occupy more than one register, the device can send bytes and words in a scrambled order, that is, out of the order they were supposed to be displayed.  The driver then allows adjusting the bytes interpretation order. To apply these settings, there are two possibilities, according to how tags are configured: either by numeric parameters (N/B) or by syntactic parameters (Device or Item). In order to figure out the order they are sent, you must check the documentation supplied by the device’s vendor.

 

Numeric parameters:

Firstly, we will present a solution which can be applied only to tags with numeric parameters (N/B).  To do so, use the driver’s settings window, go to Operations tab, and then select the operation you want to edit. After that, click Edit and check or uncheck the Swap Bytes and Swap Words options, according to the device’s standard. Finally, click OK and confirm the changes. In order to get further information on this configuration, check Byte Order at the topic Operations Tab in this driver’s documentation.

 

Syntactic parameters:

On the other hand, when the driver uses syntactic parameters (Device and Item), the configuration takes place at the Item parameter. In order to identify the data type parameter in this option, use the byte order described in the table below. For further information on this configuration, check Byte Order at the topic Strings Configuration in this driver’s documentation.

Standard

Swap Bytes Swap Words Swap DWords Order
64 bits, where by0 is lsb and b7 is msb
b0 msb by7 by6 by5 by4 by3 by2 by1 by0
b1 sb X by6 by7 by4 by5 by2 by3 by0 by1
b2 sw X by5 by4 by7 by6 by1 by0 by3 by2
b3 sb.sw X X by4 by5 by6 by7 by0 by1 by2 by3
b4 sdw X by3 by2 by1 by0 by7 by6 by5 by4
b5 sb.sdw X X by2 by3 by0 by1 by6 by7 by4 by5
b6 sw.sdw X X by1 by0 by3 by2 by5 by4 by7 by6
b7 lsb / sb.sw.sdw X X X by0 by1 by2 by3 by4 by5 by6 by7

The table below shows some examples of how to use these values to change byte order in a Holding Registers read or write operation (functions 03 and 16), address 1500 in a device with ID 5, interpreting this value as DOUBLE.

Item parameter Order
5:hr1500.d
5:hr1500.double
5:hr1500.d.b0
5:hr1500.d.msb
No bytes inversion
5:hr1500.d.b1
5:hr1500.double.b1
5:hr1500.double.sb
Less significant bytes from each Word arrive first
5:hr1500.d.b7
5:hr1500.d.lsb
5:hr1500.d.sb.sw.sdw
Less significant bytes arrive first

Related articles:


The articles below all refer to common issues faced by the Modbus driver:

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *