Today is...
Wednesday, September 20, 2017
Welcome to the Modbus Community, about
the world's leading automation protocol.
Register Reading Works on Windows, but not on Raspbian
Reading registers from slave works perfectly on Windows, but with the same settings, and query get answer, but it says invalid address.

When we connect to a Schneider EM6400 power meter using ModScan64 master on Windows, the slave sends perfect responses (we use Modbus RTU, and RS485).

But when we send query to the slave from Raspberry Pi (using the same USB-RS485 converter as on windows) we get response, but with error. We use the MinimalModBus, and a Python script:


#!/usr/bin/env python

import minimalmodbus

powermeter = minimalmodbus.Instrument('/dev/ttyUSB0',2) # serial port name, slave address (in decimal)

print "Setting serial port: \n"

powermeter.serial.baudrate = 19200
powermeter.serial.bytesize = 8

# use only one of the 3 lines below to set the parity, and remark the other two lines
powermeter.serial.parity = minimalmodbus.serial.PARITY_EVEN

powermeter.serial.stopbits = 1
powermeter.serial.timeout = 1 # seconds

print "Details of connection:\n "
print powermeter
print "\n "

powermeter.debug = True

print "Read 'Individual Parameter Address' (line to line avg voltage)register from slave:\n "
print powermeter.read_register(3903, 2)

The relevant parts of the response:


Writing to instrument: '\x02\x03\x0f?\00\x01\xb7!' (02 03 0F 3F 00 01 B7 21)
Response from instrument: '\x02\x83\x020\xf1' (02 83 03 30 F1)

What could be the problem? If it is the USB-RS485 stick, why we get the response at all?

Has anybody an idea?

1 out of 1 members thought this post was helpful...

You're right, it's not the USB/RS-485 converter.

You've asked FC03 to read one register. The error code is 03 "Illegal Data Value".

Here's what the MODBUS Spec says that error code means:

"A value contained in the query data field is not an allowable value for server (or slave). This indicates a fault in the structure of the remainder of a complex request, such as that the implied length is incorrect. It specifically does NOT mean that a data item submitted for storage in a register has a value outside the expectation of the application program, since the MODBUS protocol is unaware of the significance of any particular value of any particular register."

1. If the data value is a real/float, a long integer or some other multi-register data value, the slave might be smart enough to tell you that you've asked for only half the bits necessary. Are you sure the data you're looking for is single register? Do you need to request two registers?

2. Modscan uses one-based decimal addressing. You might have miscalculated the hex register 'starting' address with its value being off by one, so it might be reading a null register or part of a multi-register value. Try changing the starting register address by one.

Dear David,

Thanks for your reply. I'll check your suggestions.

Regards,
Csaba