pymodbus TCP客户端时间OU

2024-04-29 10:00:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我对pymodbus TcpClient超时有问题:

import logging
from pymodbus.client.sync import ModbusTcpClient

logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)

client = ModbusTcpClient('x.y.z.w', port=yyy)
client.connect()

result = client.read_holding_registers(10, 10)
print(result.registers)
client.close()

错误:

^{pr2}$

tiomeot=1的Modpool出错:

modpoll.exe -c 5 -r 10 -o 1 -p yyy -m tcp x.y.z.w
-- Polling slave... (Ctrl-C to stop)
Reply time-out!

但当timeout=10时所有货物:

modpoll.exe -c 5 -r 10 -o 10 -p yyy -m tcp x.y.z.w
-- Polling slave... (Ctrl-C to stop)
[10]: 2
[11]: 10
[12]: 10
[13]: 10

  • 如何更改pymodbus TcpClient中的默认超时?在

Tags: importclientlogloggingresultexeslavepymodbus
2条回答
from pymodbus.constants import Defaults

Defaults.Timeout = 10
client = ModbusTcpClient('x.y.z.w', port=yyy)
client.connect()

ModbusTcpClient类的构造函数或特定方法中没有任何参数来将timeout传递给该类。相反,可以通过使用Defaults全局更改timeout变量来更改类的timeout变量,从而影响ModbusTcpClient连接{}变量。在

试试看

client = ModbusTcpClient('x.y.z.w', port=yyy, timeout=10)

它适用于pymodbus中的rtu。在

相关问题 更多 >