-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
If the slave stops, the UDP client realized with pymodbus hangs (on OS X). There seems to be no way to specify a timeout on the underlying socket as for the ModbusSerialClient. The following would allow to use a timeout argument using the newly passed down kwargs.
class ModbusUdpClient(BaseModbusClient):
def __init__(self, host='127.0.0.1', port=Defaults.Port,
framer=ModbusSocketFramer, **kwargs):
''' Initialize a client instance
:param host: The host to connect to (default 127.0.0.1)
:param port: The modbus port to connect to (default 502)
:param framer: The modbus framer to use (default ModbusSocketFramer)
'''
self.host = host
self.port = port
self.socket = None
self.timeout = kwargs.get('timeout', Defaults.Timeout)
BaseModbusClient.__init__(self, framer(ClientDecoder()),**kwargs)
def connect(self):
''' Connect to the modbus tcp server
:returns: True if connection succeeded, False otherwise
'''
if self.socket: return True
try:
family = ModbusUdpClient._get_address_family(self.host)
self.socket = socket.socket(family, socket.SOCK_DGRAM)
self.socket.settimeout(self.timeout)
except socket.error, ex:
_logger.error('Unable to create udp socket %s' % ex)
self.close()
return self.socket != NoneAn update on the python3 build would be nice too.
Thanks,
Marko
Metadata
Metadata
Assignees
Labels
No labels