Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 一次不能读取超过13个寄存器_Python 3.x_Modbus_Serial Communication_Pymodbus - Fatal编程技术网

Python 3.x 一次不能读取超过13个寄存器

Python 3.x 一次不能读取超过13个寄存器,python-3.x,modbus,serial-communication,pymodbus,Python 3.x,Modbus,Serial Communication,Pymodbus,这是我的代码: from pymodbus.client.sync import ModbusSerialClient as ModbusClient client = ModbusClient(method='rtu', port='COM7', timeout=1,parity='N', baudrate=9600, unit=1) status = client.connect() print(status) rr = client.read_holding_registers(2, 2

这是我的代码:

from pymodbus.client.sync import ModbusSerialClient as ModbusClient
client = ModbusClient(method='rtu', port='COM7', timeout=1,parity='N', 
baudrate=9600, unit=1)
status = client.connect()
print(status)
rr = client.read_holding_registers(2, 20, unit=1)
print(i, rr.registers)
我得到以下错误:

print(i, rr.registers)
AttributeError: 'ModbusIOException' object has no attribute 'registers'
但是,如果读取的寄存器数达到13,则不会出现任何错误。通过使用此代码,我发现:

from pymodbus.client.sync import ModbusSerialClient as ModbusClient
client = ModbusClient(method='rtu', port='COM7', timeout=1,parity='N', 
baudrate=9600, unit=1)
status = client.connect()
print(status)
for i in range(1,20):
    rr = client.read_holding_registers(2, i, unit=1)
    print(i, rr.registers)
输出:

True
1 [0]
2 [0, 1]
3 [0, 1, 0]
4 [0, 1, 0, 2]
5 [0, 1, 0, 2, 0]
6 [0, 1, 0, 2, 0, 3]
7 [0, 1, 0, 2, 0, 3, 0]
8 [0, 1, 0, 2, 0, 3, 0, 0]
9 [0, 1, 0, 2, 0, 3, 0, 0, 0]
10 [0, 1, 0, 2, 0, 3, 0, 0, 0, 0]
11 [0, 1, 0, 2, 0, 3, 0, 0, 0, 0, 0]
12 [0, 1, 0, 2, 0, 3, 0, 0, 0, 0, 0, 0]
13 [0, 1, 0, 2, 0, 3, 0, 0, 0, 0, 0, 0, 0]
Traceback (most recent call last):
print(i, rr.registers)
AttributeError: 'ModbusIOException' object has no attribute 'registers'

您有关于服务器(从机)的更多信息吗?可能从机没有该寄存器?您是否尝试过通过单个寄存器读取直接访问它?或者,从机的TX缓冲区有限,无法在同一个包中发送超过13个寄存器?Hi@Tagli。奴隶有那个登记册。我可以通过读取一个寄存器直接访问它。从机没有限制,因为当我在raspberry pi(Raspbian OS)中运行我的代码时,它成功地执行了。但不是在我的电脑(Windows7)中。嗨@Bosz。从机是一个软件而不是一个物理软件。您可以添加用于定义从机的代码吗?您有关于服务器(从机)的更多信息吗?可能从机没有该寄存器?您是否尝试过通过单个寄存器读取直接访问它?或者,从机的TX缓冲区有限,无法在同一个包中发送超过13个寄存器?Hi@Tagli。奴隶有那个登记册。我可以通过读取一个寄存器直接访问它。从机没有限制,因为当我在raspberry pi(Raspbian OS)中运行我的代码时,它成功地执行了。但不是在我的电脑(Windows7)中。嗨@Bosz。从机是一个软件而不是一个物理软件。您可以添加用于定义从机的代码吗?