Hello, I got a device from which I require to read values from I am using a WAGO PLC 750-8212 and I am communicating through Modbus Master FUNCTION BLOCK from library WagoAppPLCModbus in Codesys 3.5 to this device. I already receive data from the device that is a CVM to monitor voltage from a fuel cell. The technical support of the company that makes these devices says that the data is sent in little endian form. And I want to convert it to a float value. The tech support sent me the next instructions of how to do it but I am new using codesys, so any advice or help I will really appreciate so much.
Message from tech support:
The process is complicated, better to do it with already implemented library in the language/program you use.
Basically the process should be next:
To convert the two Modbus registers containing parts of a 32-bit float in little-endian byte order to a floating-point number using mathematical operations, you first need to combine the two 16-bit integers (assuming reg1 is the lower word and reg2 is the higher word) and then interpret the result according to the IEEE 754 standard.
Given:
Register 192 (reg1) = 4096
Register 193 (reg2) = 14884
Step 1: Combine the two registers. Since we are dealing with little-endian byte order, reg2 is the high word, and reg1 is the low word:
The mantissa in IEEE 754 format is the fractional part after the leading 1 (which is implicit). Therefore, we need to convert the binary mantissa to decimal and add the implicit leading 1:
Hello, I got a device from which I require to read values from I am using a WAGO PLC 750-8212 and I am communicating through Modbus Master FUNCTION BLOCK from library WagoAppPLCModbus in Codesys 3.5 to this device. I already receive data from the device that is a CVM to monitor voltage from a fuel cell. The technical support of the company that makes these devices says that the data is sent in little endian form. And I want to convert it to a float value. The tech support sent me the next instructions of how to do it but I am new using codesys, so any advice or help I will really appreciate so much.
Message from tech support:
The process is complicated, better to do it with already implemented library in the language/program you use.
Basically the process should be next:
To convert the two Modbus registers containing parts of a 32-bit float in little-endian byte order to a floating-point number using mathematical operations, you first need to combine the two 16-bit integers (assuming
reg1is the lower word andreg2is the higher word) and then interpret the result according to the IEEE 754 standard.Given:
reg1) = 4096reg2) = 14884Step 1: Combine the two registers. Since we are dealing with little-endian byte order,
reg2is the high word, andreg1is the low word:Step 2: Convert the
combinedvalue to binary:Step 3: Split the binary into IEEE 754 components:
Step 4: Convert the binary exponent to decimal and subtract the bias (127 for 32-bit floats):
Step 5: Calculate the mantissa as a fraction:
The mantissa in IEEE 754 format is the fractional part after the leading 1 (which is implicit). Therefore, we need to convert the binary mantissa to decimal and add the implicit leading 1:
Step 6: Combine the sign, exponent, and mantissa to get the float value:
Because the exponent is quite large, the resulting float value is a very large number.
Maybe try going back to step one and:
Just tried and returns the same value but in scientific notation.