首页 文章

RS485 Modbus-RTU设备给出的错误是什么?

提问于
浏览
1

我使用minimalmodbus使用USB-RS485 adapter cable通过RS485与PID controller (Love 16C-3)进行通信 .

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

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

1 回答

  • 0

    如果您参考modbus规范,您会发现函数的异常是通过在函数字节中设置MSB来实现的...有效地将0x80添加到答复中的函数号 .

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

    在Modbus规范中,当不支持寄存器地址时,使用异常代码2 .

    BTW,modbus是一个非常简单的协议,原始规格本身很小,很容易获得 . 如果您计划在任何深度使用modbus,我强烈建议至少手头有这个:Modbus Application Protocol v1.1

相关问题