@@ -92,7 +92,7 @@ def checkFrame(self):
9292 crc = self ._buffer [frame_size - 2 :frame_size ]
9393 crc_val = (byte2int (crc [0 ]) << 8 ) + byte2int (crc [1 ])
9494 return checkCRC (data , crc_val )
95- except (IndexError , KeyError ):
95+ except (IndexError , KeyError , struct . error ):
9696 return False
9797
9898 def advanceFrame (self ):
@@ -243,9 +243,8 @@ def sendPacket(self, message):
243243 :param message: Message to be sent over the bus
244244 :return:
245245 """
246- # _logger.debug("Current transaction state - {}".format(
247- # ModbusTransactionState.to_string(self.client.state))
248- # )
246+ start = time .time ()
247+ timeout = start + self .client .timeout
249248 while self .client .state != ModbusTransactionState .IDLE :
250249 if self .client .state == ModbusTransactionState .TRANSACTION_COMPLETE :
251250 ts = round (time .time (), 6 )
@@ -267,8 +266,13 @@ def sendPacket(self, message):
267266 time .sleep (self .client .silent_interval )
268267 self .client .state = ModbusTransactionState .IDLE
269268 else :
270- _logger .debug ("Sleeping" )
271- time .sleep (self .client .silent_interval )
269+ if time .time () > timeout :
270+ _logger .debug ("Spent more time than the read time out, "
271+ "resetting the transaction to IDLE" )
272+ self .client .state = ModbusTransactionState .IDLE
273+ else :
274+ _logger .debug ("Sleeping" )
275+ time .sleep (self .client .silent_interval )
272276 size = self .client .send (message )
273277 # if size:
274278 # _logger.debug("Changing transaction state from 'SENDING' "
0 commit comments