@@ -29,15 +29,15 @@ class BaseModbusClient(ModbusClientMixin):
2929 framer.
3030 '''
3131
32- def __init__ (self , framer , ** kwargs ):
32+ def __init__ (self , framer ):
3333 ''' Initialize a client instance
3434
3535 :param framer: The modbus framer implementation to use
3636 '''
3737 self .framer = framer
3838 if isinstance (self .framer , ModbusSocketFramer ):
39- self .transaction = DictTransactionManager (self , ** kwargs )
40- else : self .transaction = FifoTransactionManager (self , ** kwargs )
39+ self .transaction = DictTransactionManager (self )
40+ else : self .transaction = FifoTransactionManager (self )
4141
4242 #-----------------------------------------------------------------------#
4343 # Client interface
@@ -113,22 +113,19 @@ class ModbusTcpClient(BaseModbusClient):
113113 ''' Implementation of a modbus tcp client
114114 '''
115115
116- def __init__ (self , host = '127.0.0.1' , port = Defaults .Port ,
117- framer = ModbusSocketFramer , ** kwargs ):
116+ def __init__ (self , host = '127.0.0.1' , port = Defaults .Port , framer = ModbusSocketFramer ):
118117 ''' Initialize a client instance
119118
120119 :param host: The host to connect to (default 127.0.0.1)
121120 :param port: The modbus port to connect to (default 502)
122- :param source_address: The source address tuple to bind to (default ('', 0))
123121 :param framer: The modbus framer to use (default ModbusSocketFramer)
124122
125123 .. note:: The host argument will accept ipv4 and ipv6 hosts
126124 '''
127125 self .host = host
128126 self .port = port
129- self .source_address = kwargs .get ('source_address' , ('' , 0 ))
130127 self .socket = None
131- BaseModbusClient .__init__ (self , framer (ClientDecoder ()), ** kwargs )
128+ BaseModbusClient .__init__ (self , framer (ClientDecoder ()))
132129
133130 def connect (self ):
134131 ''' Connect to the modbus tcp server
@@ -137,10 +134,8 @@ def connect(self):
137134 '''
138135 if self .socket : return True
139136 try :
140- address = (self .host , self .port )
141- self .socket = socket .create_connection ((self .host , self .port ),
142- timeout = Defaults .Timeout , source_address = self .source_address )
143- except socket .error , msg :
137+ self .socket = socket .create_connection ((self .host , self .port ), Defaults .Timeout )
138+ except socket .error as msg :
144139 _logger .error ('Connection to (%s, %s) failed: %s' % \
145140 (self .host , self .port , msg ))
146141 self .close ()
@@ -190,20 +185,17 @@ class ModbusUdpClient(BaseModbusClient):
190185 ''' Implementation of a modbus udp client
191186 '''
192187
193- def __init__ (self , host = '127.0.0.1' , port = Defaults .Port ,
194- framer = ModbusSocketFramer , ** kwargs ):
188+ def __init__ (self , host = '127.0.0.1' , port = Defaults .Port , framer = ModbusSocketFramer ):
195189 ''' Initialize a client instance
196190
197191 :param host: The host to connect to (default 127.0.0.1)
198192 :param port: The modbus port to connect to (default 502)
199193 :param framer: The modbus framer to use (default ModbusSocketFramer)
200- :param timeout: The timeout to use for this socket (default None)
201194 '''
202- self .host = host
203- self .port = port
204- self .socket = None
205- self .timeout = kwargs .get ('timeout' , None )
206- BaseModbusClient .__init__ (self , framer (ClientDecoder ()), ** kwargs )
195+ self .host = host
196+ self .port = port
197+ self .socket = None
198+ BaseModbusClient .__init__ (self , framer (ClientDecoder ()))
207199
208200 @classmethod
209201 def _get_address_family (cls , address ):
@@ -228,8 +220,7 @@ def connect(self):
228220 try :
229221 family = ModbusUdpClient ._get_address_family (self .host )
230222 self .socket = socket .socket (family , socket .SOCK_DGRAM )
231- self .socket .settimeout (self .timeout )
232- except socket .error , ex :
223+ except socket .error as ex :
233224 _logger .error ('Unable to create udp socket %s' % ex )
234225 self .close ()
235226 return self .socket != None
@@ -295,7 +286,7 @@ def __init__(self, method='ascii', **kwargs):
295286 '''
296287 self .method = method
297288 self .socket = None
298- BaseModbusClient .__init__ (self , self .__implementation (method ), ** kwargs )
289+ BaseModbusClient .__init__ (self , self .__implementation (method ))
299290
300291 self .port = kwargs .get ('port' , 0 )
301292 self .stopbits = kwargs .get ('stopbits' , Defaults .Stopbits )
@@ -319,7 +310,7 @@ def __implementation(method):
319310 raise ParameterException ("Invalid framer method requested" )
320311
321312 def connect (self ):
322- ''' Connect to the modbus serial server
313+ ''' Connect to the modbus tcp server
323314
324315 :returns: True if connection succeeded, False otherwise
325316 '''
@@ -328,7 +319,7 @@ def connect(self):
328319 self .socket = serial .Serial (port = self .port , timeout = self .timeout ,
329320 bytesize = self .bytesize , stopbits = self .stopbits ,
330321 baudrate = self .baudrate , parity = self .parity )
331- except serial .SerialException , msg :
322+ except serial .SerialException as msg :
332323 _logger .error (msg )
333324 self .close ()
334325 return self .socket != None
0 commit comments