Search code examples
modbus

Need help understanding a return value from modbus


I am reading a temperature value from a Modbus device. The value I get is 16808 and 18806 these two values are equal to 21c and 20.75. Can anyone tell me how 16808 = 21 or 18806 = 20.75?


Solution

  • The first step should be to check the manual for the device (they are often quite bad but should provide you with a starting point!). I'm going to assume that you don't have access to that and suggest a possible way forward which involves some guesswork (and is far from guaranteed!). It's important to note that you may arrive at the wrong solution by doing this (I have previously been sure I had the right encoding only to find that the byte order/endianness was wrong which led to subtle errors). It is also important to note that the values returned by some devices need to be plugged into formulae to get the end result (so guessing may be impossible!).

    16808 is 0x41A8 (in hexadecimal) - you really should work with the raw data returned (just converting to decimal requires some assumptions). Lets plug that into this converter (provides a quick way to assess possible decodings). If you do this you will note that the "Float - Big Endian (ABCD)" decoding for 41 A8 00 00 is 21 (the target value). Based on this my guess would be that this float is spread across two registers (the second register may be 0 or it might be that the units display is rounding the result for display - e.g. 41a80f11 would be 21.0074).

    18806 is 0x4976; plugging that into the converter does not lead to anything that looks promising. My next step would be to look at the registers on either side of this (especially if it's from the same device as the first value which appear likely to be 32 bit values). However I cannot see any obvious decoding that results in 20.75 - sorry.