我对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()
错误:
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] ╧юфъы■ўхэшх эх єёЄрэютыхэю,
使用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!
但对于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
发布于 2015-11-30 13:27:35
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
变量。
发布于 2014-07-29 09:29:15
试一试
client = ModbusTcpClient('x.y.z.w', port=yyy, timeout=10)
它适用于pymodbus中的rtu。
发布于 2022-11-18 13:20:44
对我来说,标准设置超时似乎不起作用。
try:
client = AsyncModbusTcpClient('x.y.z.w', port=502, timeout=10)
await client.connect()
rr = await client.read_holding_registers(offset_base, 100)
if rr.isError():
print(f' problem reading registers: {rr}')7
else:
print(f'\n regs: {rr.registers}')
except Exception as e: #asyncio.TimeoutError?
print(f'read_holding_registers :{repr(e)} -> {e.__doc__}')
这偶尔会导致:"TimeoutError() ->操作超过了给定的截止日期。“
2-使用这种方法也不起作用。从pymodbus.constants导入默认设置为Defaults.Timeout = 10 #,而不是3
3.我的尝试/错误解决方案是改变modbus包中的constants.py;
例如,Timeout =3(默认)为6。
如果我看日志记录的话,似乎是有效的,但是这是一种方式还是一个bug.?
https://stackoverflow.com/questions/23887184
复制相似问题