4141use_periphery = False
4242use_serial_lock = False
4343
44- if sys .implementation .name == 'cpython' and (sys .platform == 'linux' or sys .platform == 'linux2' ):
44+ if sys .implementation .name == 'cpython' and (sys .platform == 'linux'
45+ or sys .platform == 'linux2' ):
4546 use_periphery = True
4647 from periphery import I2C
4748
4849 use_serial_lock = True
4950 from filelock import FileLock
5051 from filelock import Timeout as SerialLockTimeout
5152else :
53+
5254 class SerialLockTimeout (Exception ):
5355 """A null SerialLockTimeout for when use_serial_lock is False."""
5456
5557 pass
5658
59+
5760use_i2c_lock = not use_periphery and sys .implementation .name != 'micropython'
5861
5962NOTECARD_I2C_ADDRESS = 0x17
@@ -310,9 +313,9 @@ def Transaction(self, req, lock=True):
310313 if rsp_expected :
311314 while retries_left > 0 :
312315 try :
313- rsp_bytes = self ._transact (
314- req_bytes , rsp_expected = True ,
315- timeout_secs = timeout_secs )
316+ rsp_bytes = self ._transact (req_bytes ,
317+ rsp_expected = True ,
318+ timeout_secs = timeout_secs )
316319 except Exception as e :
317320 if self ._debug :
318321 print (e )
@@ -344,7 +347,7 @@ def Transaction(self, req, lock=True):
344347 continue
345348
346349 if 'err' in rsp_json :
347- if '{io}' in rsp_json ['err' ]:
350+ if '{io}' in rsp_json ['err' ] and '{not-supported}' not in rsp_json [ 'err' ] :
348351 if self ._debug :
349352 print ('Response has error field indicating ' + \
350353 f'I/O error: { rsp_json } ' )
@@ -366,7 +369,8 @@ def Transaction(self, req, lock=True):
366369 break
367370 else :
368371 try :
369- self ._transact (req_bytes , rsp_expected = False ,
372+ self ._transact (req_bytes ,
373+ rsp_expected = False ,
370374 timeout_secs = timeout_secs )
371375 except Exception as e :
372376 error = True
@@ -423,7 +427,9 @@ def SetTransactionPins(self, rtx_pin, ctx_pin):
423427class OpenSerial (Notecard ):
424428 """Notecard class for Serial communication."""
425429
426- def _transact (self , req_bytes , rsp_expected ,
430+ def _transact (self ,
431+ req_bytes ,
432+ rsp_expected ,
427433 timeout_secs = CARD_INTER_TRANSACTION_TIMEOUT_SEC ):
428434 self .transmit (req_bytes )
429435
@@ -441,7 +447,8 @@ def _transact(self, req_bytes, rsp_expected,
441447
442448 return self .receive ()
443449
444- def receive (self , timeout_secs = CARD_INTRA_TRANSACTION_TIMEOUT_SEC ,
450+ def receive (self ,
451+ timeout_secs = CARD_INTRA_TRANSACTION_TIMEOUT_SEC ,
445452 delay = True ):
446453 """Read a newline-terminated batch of data from the Notecard."""
447454 data = bytearray ()
@@ -638,7 +645,8 @@ def _write(self, data):
638645 """Perform a serial-over-I2C write."""
639646 self ._platform_write (bytearray ([len (data )]), data )
640647
641- def receive (self , timeout_secs = CARD_INTRA_TRANSACTION_TIMEOUT_SEC ,
648+ def receive (self ,
649+ timeout_secs = CARD_INTRA_TRANSACTION_TIMEOUT_SEC ,
642650 delay = True ):
643651 """Read a newline-terminated batch of data from the Notecard."""
644652 read_len = 0
@@ -709,7 +717,9 @@ def transmit(self, data, delay=True):
709717 if delay :
710718 time .sleep (CARD_REQUEST_I2C_CHUNK_DELAY_MS / 1000 )
711719
712- def _transact (self , req_bytes , rsp_expected ,
720+ def _transact (self ,
721+ req_bytes ,
722+ rsp_expected ,
713723 timeout_secs = CARD_INTER_TRANSACTION_TIMEOUT_SEC ):
714724 self .transmit (req_bytes )
715725
0 commit comments