Skip to content

Commit 88f298a

Browse files
semyontdhoomakethu
authored andcommitted
Enhancement ModbusTcpClient Timeout (#140)
* Enhancement ModbusTcpClient Timeout Today Scenario: when creating a TCP Client the Defaults timeout is Always used Enhancement Scenario: pool of clients with different timeouts (more like a UDP client that accepts different timeout on context) * python 3 support
1 parent 2784ea7 commit 88f298a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pymodbus/client/sync.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def __init__(self, host='127.0.0.1', port=Defaults.Port,
121121
:param host: The host to connect to (default 127.0.0.1)
122122
:param port: The modbus port to connect to (default 502)
123123
:param source_address: The source address tuple to bind to (default ('', 0))
124+
:param timeout: The timeout to use for this socket (default Defaults.Timeout)
124125
:param framer: The modbus framer to use (default ModbusSocketFramer)
125126
126127
.. note:: The host argument will accept ipv4 and ipv6 hosts
@@ -129,6 +130,7 @@ def __init__(self, host='127.0.0.1', port=Defaults.Port,
129130
self.port = port
130131
self.source_address = kwargs.get('source_address', ('', 0))
131132
self.socket = None
133+
self.timeout = kwargs.get('timeout', Defaults.Timeout)
132134
BaseModbusClient.__init__(self, framer(ClientDecoder()), **kwargs)
133135

134136
def connect(self):
@@ -140,7 +142,7 @@ def connect(self):
140142
try:
141143
address = (self.host, self.port)
142144
self.socket = socket.create_connection((self.host, self.port),
143-
timeout=Defaults.Timeout, source_address=self.source_address)
145+
timeout=self.timeout, source_address=self.source_address)
144146
except socket.error as msg:
145147
_logger.error('Connection to (%s, %s) failed: %s' % \
146148
(self.host, self.port, msg))

0 commit comments

Comments
 (0)