@@ -249,10 +249,6 @@ def __init__(self, debug:bool = False) -> None:
249
249
250
250
# Initialize USB connection and start worker thread
251
251
self ._open_port ()
252
- self .worker_thread = threading .Thread (target = self .__updatestate ,
253
- args = (self .child_pipe ,))
254
- self .worker_thread .daemon = True
255
- self .worker_thread .start ()
256
252
257
253
def __del__ (self ) -> None :
258
254
if not self .simulated :
@@ -420,12 +416,7 @@ def __sendcmd(self, cmd:Union[List[int],bytes]) -> None:
420
416
if isinstance (cmd , list ):
421
417
cmd = bytes (cmd )
422
418
423
- # For R2, ensure command is properly formatted with CRC
424
- if len (cmd ) == 4 : # Basic command without CRC
425
- cmd_with_crc = self .prepare_command (cmd )
426
- self .ep_out .write (cmd_with_crc , timeout = self .TIMEOUT )
427
- else : # Command already has CRC
428
- self .ep_out .write (cmd , timeout = self .TIMEOUT )
419
+ self .ep_out .write (cmd , timeout = self .TIMEOUT )
429
420
430
421
except Exception as e : # pylint: disable=broad-except
431
422
raise OSError (f'Failed to send command: { str (e )} ' ) from e
@@ -606,6 +597,8 @@ def __updatestate(self, p:'Connection') -> None:
606
597
f"active_power: { self .active_power :.1f} , reactive_power: { self .reactive_power :.1f} , apparent_power: { self .apparent_power :.1f} , "
607
598
f"voltage_rms: { self .voltage_rms :.1f} V, current_rms: { self .current_rms :.1f} A " )
608
599
600
+ else :
601
+ pass #unparsed
609
602
610
603
# Check for and handle commands from the pipe
611
604
try :
@@ -674,8 +667,6 @@ def prepare_command(self, cmd:Union[List[int],bytes]) -> bytes:
674
667
if isinstance (cmd , list ):
675
668
cmd = bytes (cmd )
676
669
cmd_with_crc = bytearray (cmd )
677
- while len (cmd_with_crc ) < 60 :
678
- cmd_with_crc .extend ([0 ])
679
670
cmd_with_crc .extend ([0 , 0 , 0 , 0 ])
680
671
crc = self .calculate_crc32 (bytes (cmd_with_crc ))
681
672
cmd_with_crc [- 4 :] = crc .to_bytes (4 , 'little' )
0 commit comments