Getting a wrong Data While reading a value from register using Modbus


I am using RModbus gem for the last 3 years and now a days we are using Modbus as the client and reading/writing register using the defined implementations. In recent times we are experiencing that while reading a register sometimes (2-3 times out of 10) getting random values which is out of context for the register. Also in the response during the reading process, there is no exception when we are getting the wrong value. But most of the time the value defined for register we are getting. We are not sure is there any configuration/ request needs to be updated to get the actual value for the register.

For example, we have a register and the value of the register is set to 1500 but if we read the same register 10 times, we may not get 1500 at all the request.

I would request to please share your thoughts. Any help will be highly appreciated.

I recommend you start by determining whether this is an issue with your Modbus client or the Modbus server. Try using a third-party Modbus client such as ModScan or Modbus Poll to read the register from the Modbus server. If you see the same behavior, then the issue is with the Modbus server.

If you do not, then the issue may be with your Modbus client. One way to definitively determine if the issue is indeed with your client is to capture the Modbus packets and check if any of the captured responses from the server have unexpected values.
Long time ago, in the past, I had during my times at Philips a serial communication card with 4 serial ports. I could set it into RAW fully transparant mode and an "interpret" mode. Of course I set it to transparant because my data bytes could be anything from 0 to 255.
It happened that 2 of the 4 ports were not 100% transparent (when set) and when a backspace character (decimal 8) was in the string, the communication port interpreted the backspace and cut off the block check BCC character.

I know it is a very long shot.........but is it that your port is maybe not fully 100% transparent? It happened only to me when the BCC character was 08 (backspace). And it was really difficult to find.

Also try with another number like 1500.

Use a modbus sniffer on the bus to figure out what data is going over the bus.