1

I am using minimalmodbus to communicate with a PID controller (Love 16C-3) via RS485 using a USB-RS485 adapter cable.

However when trying to read the register, the following error is shown. What does this error mean?

raise ValueError('The slave is indicating an error. The response is: {!r}'.format(response))
ValueError: The slave is indicating an error. The response is: '\x01\x83\x02\xc0\xf1'

From Hardware's Manual

enter image description here

Python Code

instrument = minimalmodbus.Instrument(port, 1, 'rtu')
instrument.serial.baudrate = 9600
instrument.serial.bytesize=8
instrument.serial.parity='E'
instrument.serial.stopbits=1
instrument.read_register(4096,1)

enter image description here

Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
  • Looks like `Illegal Data Address` exception. See [modbus exceptions](http://www.simplymodbus.ca/exceptions.htm). – Andrej Debenjak Dec 05 '16 at 22:01
  • Try `instrument.read_register(0x4700,1)` – Andrej Debenjak Dec 05 '16 at 22:11
  • @AndrejDebenjak Thanks, fixed the address and solved the problem. How do you tell that error message `\x01\x83\x02\xc0\xf1` meant `Illegal Data Address`? – Nyxynyx Dec 05 '16 at 22:12
  • The second number in the response: `83` – Andrej Debenjak Dec 05 '16 at 22:14
  • @AndrejDebenjak Sorry I dont see an error code `83` in the modbus exceptions page you linked... – Nyxynyx Dec 05 '16 at 22:17
  • 2
    Sorry, bad answer. You received `'\x01\x83\x02\xc0\xf1'`. The first number is the slave's address. The second one is function code `0x83`, which represents exception to a register read command. The third number tells you exactly which exception occured - `0x02` meaning `Illegal Data Address` exception. The last two numbers are CRC. – Andrej Debenjak Dec 05 '16 at 22:46
  • @AndrejDebenjak Thank you! Solved. – Nyxynyx Dec 05 '16 at 23:33

1 Answers1

1

If you reference the modbus spec, you find that an exception to a function is made by setting the MSB in the function byte... effectively adding 0x80 to the function number in the reply.

In your example, you attempted to read Holding register. Your request used a function number of 0x03. The exception you received is that function 0x03 with the MSB set high, resulting in a reply function of 0x83. The exception code is the number that follows the function number, in your case it is 0x02.

In the Modbus Spec, an exception code of 2 is used when the register address is not supported.

BTW, modbus is an exceedingly simply protocol, and the original spec itself is quite small and easily available. If you plan on working with modbus at any depth, I would highly recommend at least having it at hand: Modbus Application Protocol v1.1