drbitboy
Lifetime Supporting Member
The topic of reading or writing floating-point values via Modbus seems to come up regularly, and it is to my mind not that difficult.
That said, it is opaque and somewhat tedious to deal with, there may be few diagnostic tools available, and not everyone natively reads the bits of IEEE-754 format.
To try to ameliorate that, I wrote a Visual Basic (VB) application to return all possible byte- and word-order combinations from a single floating-point value; one of them should be the correct value; see below. The idea is straightforward: say you are reading two 16-bit words from a Modbus server, and a naive COPy on the PLC from a word pair to 32-bit float yields 5.900879e-39, when you know the value is around 12.0. You can use the app (first image below) to create a minimal Modbus pseudo-server (RTU) that sends all 24 four-byte possible combinations (48 words; 96 bytes) of the data that yield that value. The second image shows a MicroLogix program using a MSG instruction as a Modbus client to retrieve the 48 16-bit words and COPying them into 24 32-bit REALs. You can see that F254:5 and F254:16 are both 12.00006 (two of the four bytes are the same) and is likely to be the right answer, and the hexadecimal values show in the VB app (top image) would guide you to understanding how to achieve that result.
At some point I'll put this on Github and the Download area here; it should be possible to add Modbus TCP capability.
That said, it is opaque and somewhat tedious to deal with, there may be few diagnostic tools available, and not everyone natively reads the bits of IEEE-754 format.
To try to ameliorate that, I wrote a Visual Basic (VB) application to return all possible byte- and word-order combinations from a single floating-point value; one of them should be the correct value; see below. The idea is straightforward: say you are reading two 16-bit words from a Modbus server, and a naive COPy on the PLC from a word pair to 32-bit float yields 5.900879e-39, when you know the value is around 12.0. You can use the app (first image below) to create a minimal Modbus pseudo-server (RTU) that sends all 24 four-byte possible combinations (48 words; 96 bytes) of the data that yield that value. The second image shows a MicroLogix program using a MSG instruction as a Modbus client to retrieve the 48 16-bit words and COPying them into 24 32-bit REALs. You can see that F254:5 and F254:16 are both 12.00006 (two of the four bytes are the same) and is likely to be the right answer, and the hexadecimal values show in the VB app (top image) would guide you to understanding how to achieve that result.
At some point I'll put this on Github and the Download area here; it should be possible to add Modbus TCP capability.