2016-12-05 125 views
0

我使用minimalmodbus通过RS485使用USB-RS485 adapter cablePID controller (Love 16C-3)通信。RS485 Modbus-RTU设备给出的这个错误是什么

但是,当试图读取寄存器时,会显示以下错误。这个错误是什么意思?

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' 

从硬件手册

enter image description here

Python代码

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

+0

看起来像'非法数据地址'异常。参见[modbus例外](http://www.simplymodbus.ca/exceptions.htm)。 –

+0

尝试'instrument.read_register(0x4700,1)' –

+0

@AndrejDebenjak谢谢,修正了地址并解决了问题。你如何知道错误信息'\ x01 \ x83 \ x02 \ xc0 \ xf1'意味着'非法数据地址'? – Nyxynyx

回答

0

如果你参考了modbus规范,你会发现通过在函数字节中设置MSB来实现函数的一个例外......在回复函数中有效地加上0x80。

在您的示例中,您试图读取保持寄存器。您的请求使用了0x03的功能号码。您收到的异常是功能0x03,MSB置高,导致回复函数为0x83。异常代码是函数编号后面的数字,在你的情况下它是0x02。

在Modbus规格中,如果寄存器地址不受支持,则使用2的异常代码。

顺便说一句,modbus是一个非常简单的协议,原来的规格本身很小,很容易获得。如果你打算在任何深度使用modbus,我强烈建议至少把它放在手边:Modbus Application Protocol v1.1