我遇到pymodbus TcpClient超时问题:
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
from pymodbus.client.sync import ModbusTcpClient
client = ModbusTcpClient('x.y.z.w', port=yyy)
client.connect()
result = client.read_holding_registers(10, 10)
print result.registers
client.close()
错误:
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:Transaction failed. (timed out)
ERROR:pymodbus.client.sync:Connection to (x.y.z.w, yyy) failed: [Errno 10061] ╧юфъы■ўхэшх эх єёЄрэютыхэю,
modome with tiomeot = 1我有错误:
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!
但超时= 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
答案 0 :(得分:1)
尝试
client = ModbusTcpClient('x.y.z.w', port=yyy, timeout=10)
适用于pymodbus中的rtu。
答案 1 :(得分:1)
from pymodbus.constants import Defaults
Defaults.Timeout = 10
client = ModbusTcpClient('x.y.z.w', port=yyy)
client.connect()
ModbusTcpClient
类没有任何参数可以将timeout
传递给类的构造函数或特定方法。相反,可以使用timeout
全局更改timeout
变量来更改类的Defaults
,从而影响ModbusTcpClient
连接timeout
变量。