Features, discussions, tips, tricks, questions, problems and feedback

Modbus data ordering (bit, byte, word, long and float ordering)

Background

A fairly common question that is brought up when using Adroit Modbus drivers is that the value displayed in Adroit SCADA is not the same as the value read from the Programmable Logic Controller (PLC) or other Front-End Device (FED). If you are experiencing this issue, you may need to change the ordering of the data that is received. Depending on the datatype being scanned, you may need to change the settings for the byte, word, long or float ordering in the device configuration.

For a more detailed explanation of this issue, please read the PDF document attached to this article. The important descriptions and guides have been summarised later in this article.

The following Modbus drivers can utilise this setting:

  • Modbus Ethernet (mod_eth)
  • Modbus Ethernet Multi-Channel (mod_emc)
  • Modbus Serial (modbusi)

Description

In this section, navigate through to the scenario you may be experiencing based on the datatype of the address are scanning. Make sure to follow the instructions.

Navigate to the Modbus device that is affected and click on Configure.


In the dialog that appears, click on the Advanced… button.


In the Advanced dialog, you will see a groupbox section called Byte Ordering. These are the settings that will be changed to affect the value coming from the FED.

image

Please Note: For any changes to take effect, all Modbus configuration dialogs (including the Advanced and the initial dialog) must be closed using the OK button. From there, you will either need to restart your Agent server or disconnect your Modbus device from Adroit (for example, by unplugging the device) for the setting change to apply.

For more descriptions on these settings, refer to the attached PDF document or the driver documentation.

In this section, different address scanning scenarios will be considered to illustrate the impact of these settings. The main aspect to consider when dealing with these settings is that they work on top of one another. If you are trying to diagnose the issue of ordering, you will have to consider all setting combinations .

Reading an Integer from Holding Registers:

Test with different combinations of “Swap word’s byte order” setting enabled/disabled.

For example, let’s say the hexadecimal value from the field is 0x012A (decimal 298). Adroit will interpret the value in either of the two ways, depending on the setting in the Advanced Dialog:

012A (hex) -> 298

2A01 (hex) -> 10753 (example of a byte order swap)

Reading a Long from Holding Registers:

Test with different combinations of “Swap word’s byte order” setting enabled/disabled and “Swap LONG word ordering” setting enabled/disabled.

For example, the let’s say the hexadecimal values from the FED are 0xABCD in 40001 and 0x012F in the next register 40002. Scanning the address in Adroit using ‘400001 L’, Adroit can interpret the value in 4 different ways, depending on the settings combination in the Advanced Dialog:

012F ABCD (hex) -> 19901389

2F01 CDAB (hex) -> 788647339 (example of a byte order swap)

ABCD 012F (hex) -> -1412628177 (example of a word order swap)

CDAB 2F01 (hex) -> -844419327 (example with a word and byte order swap)

Reading a Float from Holding Registers:

Test with different combinations of “Swap word’s byte order” setting enabled/disabled and “Swap floating-point word ordering” setting enabled/disabled.

For example, let’s say the hexadecimal values from the FED are 0x4297 in 40001 and 0xABCD in the next register 40002. Scanning the address in Adroit using ‘400001 F’, Adroit can interpret the value in 4 different ways, depending on the settings combination in the Advanced Dialog:

4297 ABCD (hex) -> 75.835548

9742 CDAB (hex) -> -6.2944370267e-25 (-0.000000 in Adroit) (example of a byte order swap)

ABCD 4297 (hex) -> -1.45846084775e-12 (-0.00000 in Adroit) (example of a word order swap)

CDAB 9742 (hex) -> -359852096.0 (example of a word and byte order swap)

Reading a String from Holding Registers:

Test with different combinations of “Swap byte order on String agents” setting enabled/disabled.

For example, let’s say the hexadecimal values from the FED are 0x4845 (“HE” in ASCII), 0x4C4C (“LL” in ASCII) and 0x4F21 (“O!” in ASCII) in holding registers 40001, 40002 and 40003 respectively. Scanning the address in Adroit using ‘400001 C6’, Adroit can interpret the value in 2 different ways, depending on the settings combination in the Advanced Dialog:

4845 4C4C 4F21 (hex) -> HELLO!

4548 4C4C 214F (hex) -> EHLL!O

Reading multiple Boolean values from one Holding Register:

Test with different combinations of the “Reverse MSb/LSb ordering when scanning Holding register bits into Booleans” setting enabled/disabled and the “Swap word’s byte order” setting enabled/disabled.

For example, let’s say the hexadecimal value from the FED is 0xEF3C in holding register 40001. Scanning each bit address in Adroit to its own Digital agent in Adroit using ‘400001.x’ where x is the position of the bit in the integer value, Adroit can interpret the value in 2 different ways, depending on the settings combination in the Advanced Dialog:

For the following examples, notice the byte ordering and the bit ordering of those bytes and how changing the advanced settings alters the values. There is no standard correct combination, so this example is to illustrate the effect each setting has on the order of the data.

Default:


Default but only the setting “Reverse MSb/LSb ordering when scanning Holding register bits into Booleans” was changed:

MSb and LSb have been changed. Therefore, bit order has changed (effectively causing the byte order to change).

Default but only the setting “Swap word’s byte order” was changed from the default:


Notice it has the same bit order as the Default case, but the byte order is swapped.

Default but both the settings “Reverse MSb/LSb ordering when scanning Holding register bits into Booleans” and “Swap word’s byte order” were changed:


Notice in this case the bit and byte order has changed.

Additional Considerations

The examples examined previously are only one possible solution to the problem of Adroit SCADA displaying the incorrect value. If the descriptions above do not solve your issue, consider the following too:

  • Is the starting address/index correct? Eg. if you are scanning an integer at Modbus address 40002 but the actual quantity being measured is stored a Float starting from 40001.
  • Have you added a Format Identifier to your scan address? (Eg. Cx, Sx, F, L, I, etc. where x represents the number of characters in the string type) If so, have you used the correct identifier?
  • From the previous point, if the datatype you are scanning is of type Integer, is the quantity meant to be unsigned or signed? Only use the ‘I’ specifier in the scan address if it is meant to be signed (ie. Signed means it can be a negative or positive quantity, whereas unsigned can only be a positive quantity).
  • Could the value coming from the Modbus FED need to have a scaling factor?
  • Are the peripherals to the Modbus device connected correctly? Could there be a device overwriting the address you are scanning which could be affecting your output?

Conclusion

For any additional information or queries, please feel free to contact Adroit Support or search our Knowledge Base.

Modbus data ordering (bit, byte, word, long and float ordering).pdf (415.9 KB)

1 Like