2016-12-05 114 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