pymodbus TcpClient超时

时间:2014-05-27 10:34:32

标签: python connection-timeout modbus

我遇到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

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

2 个答案:

答案 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变量。