ValueError:从站指示错误。答案是:' \ x01 \ x83 \ x02 \ xc0 \ xf1' minimalmodbus

时间:2016-08-15 08:56:34

标签: python ubuntu

我是Modbus协议的新手,我使用minimalmodbus python包从Modbus RTU slave获取数据。slave是L&T Quasar Module。 Python代码如下:

import minimalmodbus
import serial
import sys
instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 1)
instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 1,mode='rtu')
instrument.mode = minimalmodbus.MODE_RTU   # rtu or ascii mode
instrument.serial.baudrate = 9600   # Baud
instrument.serial.bytesize = 8
instrument.serial.parity   = serial.PARITY_EVEN
instrument.serial.stopbits = 1
instrument.serial.timeout  = 0.05   # seconds
print instrument.read_register(30001, 2) #register address, number of registers

输出结果为:

*Traceback (most recent call last):

 File "Desktop/meter/minimal_test.py", line 16, in <module>
    print instrument.read_register(30001, 2) #register address, number of registers
  File "/usr/local/lib/python2.7/dist-packages/minimalmodbus-0.7-py2.7.egg/minimalmodbus.py", line 258, in read_register
    return self._genericCommand(functioncode, registeraddress, numberOfDecimals=numberOfDecimals, signed=signed)
  File "/usr/local/lib/python2.7/dist-packages/minimalmodbus-0.7-py2.7.egg/minimalmodbus.py", line 697, in _genericCommand
    payloadFromSlave = self._performCommand(functioncode, payloadToSlave)
  File "/usr/local/lib/python2.7/dist-packages/minimalmodbus-0.7-py2.7.egg/minimalmodbus.py", line 798, in _performCommand
    payloadFromSlave = _extractPayload(response, self.address, self.mode, functioncode)
  File "/usr/local/lib/python2.7/dist-packages/minimalmodbus-0.7-py2.7.egg/minimalmodbus.py", line 1088, in _extractPayload
    raise ValueError('The slave is indicating an error. The response is: {!r}'.format(response))

ValueError:从站指示错误。答案是:&#39; \ x01 \ x83 \ x02 \ xc0 \ xf1&#39; *

奴隶在Windows机器上使用MODSCAN按预期响应。

0 个答案:

没有答案