@@ -152,7 +152,8 @@ def __init__(
152
152
dio3_tcxo_start_time_us if dio3_tcxo_millivolts else 0
153
153
)
154
154
155
- self ._buf = bytearray (9 ) # shared buffer for commands
155
+ self ._buf = bytearray (9 ) # shared buffer for commands, access through _buf_view
156
+ self ._buf_view = memoryview (self ._buf )
156
157
157
158
# These settings are kept in the object (as can't read them back from the modem)
158
159
self ._output_power = 14
@@ -704,11 +705,11 @@ def _cmd(self, fmt, *write_args, n_read=0, write_buf=None, read_buf=None):
704
705
# have happened well before _cmd() is called again.
705
706
self ._wait_not_busy (self ._busy_timeout )
706
707
707
- # Pack write_args into _buf and wrap a memoryview of the correct length around it
708
+ # Pack write_args into slice of _buf_view memoryview of correct length
708
709
wrlen = struct .calcsize (fmt )
709
- assert n_read + wrlen <= len (self ._buf ) # if this fails, make _buf bigger!
710
- struct .pack_into (fmt , self ._buf , 0 , * write_args )
711
- buf = memoryview ( self ._buf ) [: (wrlen + n_read )]
710
+ assert n_read + wrlen <= len (self ._buf_view ) # if this fails, make _buf bigger!
711
+ struct .pack_into (fmt , self ._buf_view , 0 , * write_args )
712
+ buf = self ._buf_view [: (wrlen + n_read )]
712
713
713
714
if _DEBUG :
714
715
print (">>> {}" .format (buf [:wrlen ].hex ()))
@@ -723,7 +724,7 @@ def _cmd(self, fmt, *write_args, n_read=0, write_buf=None, read_buf=None):
723
724
self ._cs (1 )
724
725
725
726
if n_read > 0 :
726
- res = memoryview ( buf ) [wrlen : (wrlen + n_read )] # noqa: E203
727
+ res = self . _buf_view [wrlen : (wrlen + n_read )] # noqa: E203
727
728
if _DEBUG :
728
729
print ("<<< {}" .format (res .hex ()))
729
730
return res
0 commit comments