我是 modbus 的新手,我正在尝试用于 python 的 minimummodbus 库。我连接了一个设备并尝试了 minimummobus 文档提供的示例,我收到以下错误:
MinimalModbus debug mode. Create serial port COM13
MinimalModbus debug mode. Will write to instrument (expecting 7 bytes back): 01 03 00 04 00 01 C5 CB (8 bytes)
MinimalModbus debug mode. Clearing serial buffers for port COM13
MinimalModbus debug mode. No sleep required before write. Time since previous read: 7361796.00 ms, minimum silent period: 1.75 ms.
MinimalModbus debug mode. Closing port COM13
MinimalModbus debug mode. Response from instrument: 01 83 02 C0 F1 (5 bytes), roundtrip time: 30.0 ms. Timeout for reading: 0.0 ms.
Traceback (most recent call last):
File "k.py", line 15, in <module>
r=instrument.read_register(4,1,functioncode=3)
File "C:\Users\Themistoklis\AppData\Local\Programs\Python\Python36-32\lib\site-packages\minimalmodbus.py", line 486, in read_register
payloadformat=_Payloadformat.REGISTER,
File "C:\Users\Themistoklis\AppData\Local\Programs\Python\Python36-32\lib\site-packages\minimalmodbus.py", line 1245, in _generic_command
payload_from_slave = self._perform_command(functioncode, payload_to_slave)
File "C:\Users\Themistoklis\AppData\Local\Programs\Python\Python36-32\lib\site-packages\minimalmodbus.py", line 1330, in _perform_command
response, self.address, self.mode, functioncode
File "C:\Users\Themistoklis\AppData\Local\Programs\Python\Python36-32\lib\site-packages\minimalmodbus.py", line 1880, in _extract_payload
_check_response_slaveerrorcode(response)
File "C:\Users\Themistoklis\AppData\Local\Programs\Python\Python36-32\lib\site-packages\minimalmodbus.py", line 3538, in _check_response_slaveerrorcode
raise error
minimalmodbus.IllegalRequestError: Slave reported illegal data address
我的代码很简单,它遵循提供的示例
import minimalmodbus
import serial
instrument = minimalmodbus.Instrument('COM13',1,debug=True)
instrument.serial.baudrate=115200
instrument.serial.parity=serial.PARITY_EVEN
print(instrument.read_register(4,1,functioncode=3))
instrument.serial.close()
我知道 4 号寄存器是一个很好的寄存器,因为当我使用随设备提供的 Labview 示例时,我从中得到了读数。如果有人可以向我提供有关 minimummodbus 错误及其确切含义的更深入信息,我将不胜感激。