Change the byte order in a Modbus 32 bits register


I have to connect to a device using Modbus TCP protocol
I should to change the Byte order when I read a 32 bit register ( float and long) in according with Intel-formatted data.

The driver can only reverse the word order in a 32 bit register but not the byte order

Has anyone did this with ignition?

Thank you very much


Does the entire byte order need to be reversed?

If so:

[code]import struct

i = 2864434397
s= struct.unpack("<I",struct.pack(">I",i))[0]
print i, hex(i)
print s, hex(s)

For another technique, you can flip things around using some Java types:

def int32BE_to_float32LE(i): from java.lang import Float, Integer return Float.intBitsToFloat(Integer.reverseBytes(i))


Thank you very much to everybody
…two great solutions!!!