pymodbus Exception Response(131, 3, IllegalAddress)

倾然丶 夕夏残阳落幕 提交于 2019-12-23 13:09:10

问题


I'm trying to run this piece of code:

from pymodbus.client.sync import ModbusSerialClient as ModbusClient
import logging

logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)

client = ModbusClient(method='rtu', baudrate=9600, parity='E', port='/dev/ttyUSB0', timeout=1)
client.connect()

rr = client.read_holding_registers(40000, 7, unit=0x01)
print rr
client.close()

But I get only this:

DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.factory:Factory Response[131]
DEBUG:pymodbus.transaction:adding transaction 0
DEBUG:pymodbus.transaction:getting transaction 1
Exception Response(131, 3, IllegalAddress)

On the other hand this C code (using libmodbus) is working:

modbus_t *mb;
int16_t hregs[9];
mb = modbus_new_rtu('/dev/ttyUSB0', 9600, 'E', 8, 1);
modbus_set_slave(mb, 1);
modbus_read_registers(mb, 0x40000, 7, hregs)

What am I doing wrong?


回答1:


I am assuming you want to read the first seven holding registers. In that case, the address to be given to the read_holding_registers function is 0. The function implicitly adds the offset of 40000 for holding registers.

So, try changing your read code to this

rr = client.read_holding_registers(0, 7, unit=0x01)



回答2:


Exception Response(131, 3, IllegalAddress) means:

A value contained in the query data field is not an allowable value for the slave. This indicates a fault in the structure of 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.

http://www.simplymodbus.ca/exceptions.htm


[UPDATE]:

Did you try with 0x40000 or 0x400 (as a default in many cases)? 0x40000 (hexadecimal) have different with 40000 (decimal)



来源:https://stackoverflow.com/questions/33264449/pymodbus-exception-response131-3-illegaladdress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!