How does SNAP-UP1-ADS process IEEE754 data?

Excuse me, SNAP-UP1-ADS does not support the UnpackString command. Is there a way to convert four-byte IEEE754 data into floating-point numbers?
image

//If the source is a hex string:
myFloat = IEEEHexStringToNumber(source_string);

//If the source is binary and big endian:
myFloat = Int32ToFloatBits(source_string[0] << 24 + source_string[1] << 16 + source_string[2] << 8 + source_string[3]);

//09 03 18 A1 67 33 40 3D 51 27 40 77 77 93 C0 77 77 93 C0 77 77 93 C0 77 77 93 C0 02 97
//09 03 18 DE 71 0E 40 39 45 27 40 77 77 93 C0 77 77 93 C0 77 77 93 C0 77 77 93 C0 98 01
AR3012_Received_Data=chr(0x09)+chr(0x03)+chr(0x18)+chr(0xA1)+chr(0x67)+chr(0x33)+chr(0x40)+chr(0x3D)+chr(0x51)+chr(0x27)
+chr(0x40)+chr(0x77)+chr(0x77)+chr(0x93)+chr(0xc0)+chr(0x77)+chr(0x77)+chr(0x93)+chr(0xc0)+chr(0x77)+chr(0x77)
+chr(0x93)+chr(0xc0);

IEEE754_Str="";
NumberToHexString(AR3012_Received_Data[3],IEEE754_Str1);
NumberToHexString(AR3012_Received_Data[4],IEEE754_Str2);
NumberToHexString(AR3012_Received_Data[5],IEEE754_Str3);
NumberToHexString(AR3012_Received_Data[6],IEEE754_Str4);
IEEE754_Str=IEEE754_Str4+IEEE754_Str3+IEEE754_Str2+IEEE754_Str1;
AR3012_Channel_1=IEEEHexStringToNumber(IEEE754_Str);
//AR3012_Channel_1=2.8032 ok!

UnpackString(AR3012_Received_Data,3,4,AR3012_Channel_3,3,1);
//*AR3012_Channel_1=2.8032 ok!

AR3012_Channel_4=int32toFloatBits(AR3012_Received_Data[3]<<24+AR3012_Received_Data[4]<<16
+AR3012_Received_Data[5]<<8+AR3012_Received_Data[6]);
//*AR3012_Channel_4=0 ??

Looks like you are expecting the data to be little endian, so on the int32toFloatBits, change the order around:

AR3012_Channel_4=int32toFloatBits(AR3012_Received_Data[6]<<24 + AR3012_Received_Data[5]<<16 + AR3012_Received_Data[4]<<8 + AR3012_Received_Data[3]);

And yes, the Big Endian and Modbus Big Endian are the same (this is also known as “network order”) and most modern network protocols are big endian. Modbus is complete anarchy when it comes to byte order (and a bunch of other things).

1 Like