@@ -92,7 +92,7 @@ def checkFrame(self):
92
92
crc = self ._buffer [frame_size - 2 :frame_size ]
93
93
crc_val = (byte2int (crc [0 ]) << 8 ) + byte2int (crc [1 ])
94
94
return checkCRC (data , crc_val )
95
- except (IndexError , KeyError ):
95
+ except (IndexError , KeyError , struct . error ):
96
96
return False
97
97
98
98
def advanceFrame (self ):
@@ -243,9 +243,8 @@ def sendPacket(self, message):
243
243
:param message: Message to be sent over the bus
244
244
:return:
245
245
"""
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
249
248
while self .client .state != ModbusTransactionState .IDLE :
250
249
if self .client .state == ModbusTransactionState .TRANSACTION_COMPLETE :
251
250
ts = round (time .time (), 6 )
@@ -267,8 +266,13 @@ def sendPacket(self, message):
267
266
time .sleep (self .client .silent_interval )
268
267
self .client .state = ModbusTransactionState .IDLE
269
268
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 )
272
276
size = self .client .send (message )
273
277
# if size:
274
278
# _logger.debug("Changing transaction state from 'SENDING' "
0 commit comments