sending arrays with modbus TCP - wrong values received in slave PLC

hi. i am sending arrays with information from a AC500 master to AC500 slave PLC. and i ran into a problem

my arrays gets mixed up. for example if i send a variable with value 10 integer, i get 2560 in the slave PLC

. if i send value 10 real in REAL_array[3] i get 1.19 in one variable and 7.7 in another one withing the array.

i made sure to set the slave and master plc to little endian. this fixed the arrangements of my string arrays, but that's about it.

what can i do to fix this?
regards
 
You probably already suspected this, but there is some byte-shifting at play here. Keep in mind, Modbus deals only with 16-bit registers (encoded in big-endian order "on-the-wire", i.e. in the packet). Combining or splitting registers is outside the scope of the Modbus protocol itself and is solely the responsibility of the application (PLC in this case). It seems that you are encoding the Modbus values from one PLC differently from how you're decoding them in the other PLC.

It seems you are doing many complicated things that are easy to get wrong when using Modbus, i.e. encoding ASCII strings and REALs, in addition to integer values. You need to know how your PLC's are encoding and decoding the ASCII characters, REALs, and integers into the 16-bit Modbus registers. Do you have a way of viewing raw, 16-bit Modbus (hexadecimal) register values in the PLC's?

For example, assuming a standard 16-bit integer, a value of 10 (0x000A hexadecimal) would be a value of 2560 if the bytes were reversed (0x0A00 hexadecimal). So it seems one of the PLC's is byte reversing this value.

Encoding REALs (I assume these to be 32-bit IEEE 754 Single Precision Floating Point) adds even more complication. This requires using two consecutive Modbus registers. A value of 10 equates to a hexadecimal value of 0x41200000 (when using IEEE 754 encoding). Therefore, one register would have the value 0x4120 and the other 0x0000. Since two registers are required, it's possible one of the PLC's is off by a register and using values from the previous or next value in the array when trying to interpret the 32-bit REAL value.

When encoding ASCII strings, be very careful of the byte (character) ordering. Remember, all Modbus values must be 16-bits, so each register contains two ASCII characters and the order is very important. For example, a string of "Hello World!" may need to be encoded into 6 consecutive registers as "eH", "ll", " o", "oW", "lr", "!d".

It's important to note that changing a global setting, such as endianness, may make ASCII strings work, but could prevent integer encoding/decoding from working properly. You'll need to fully understand how all values are being encoded/decoded in order to determine the proper resolution.

I recommend taking a step back and using only one PLC with PC simulator software such as ModScan/ModSim. Get each PLC working with the PC software before trying to get them to communicate with each other.
 
Top