@@ -795,6 +795,7 @@ def __init__(self, windll: str, rxid: int, txid: int, name: Optional[str] = None
795
795
796
796
def open (self ) -> "J2534Connection" :
797
797
self .exit_requested = False
798
+ self .sem = threading .Semaphore ()
798
799
self .rxthread = threading .Thread (target = self .rxthread_task , daemon = True )
799
800
self .rxthread .start ()
800
801
self .opened = True
@@ -812,13 +813,16 @@ def is_open(self) -> bool:
812
813
813
814
def rxthread_task (self ) -> None :
814
815
while not self .exit_requested :
816
+ self .sem .acquire ()
815
817
try :
816
818
result , data , numMessages = self .interface .PassThruReadMsgs (self .channelID , self .protocol .value , 1 , 1 )
817
819
if data is not None :
818
820
self .rxqueue .put (data )
819
821
except Exception :
820
822
self .logger .critical ("Exiting J2534 rx thread" )
821
823
self .exit_requested = True
824
+ self .sem .release ()
825
+ time .sleep (0.001 )
822
826
823
827
def log_last_operation (self , exec_method : str , with_raise = False ) -> None :
824
828
if self .result != Error_ID .ERR_SUCCESS :
@@ -844,9 +848,13 @@ def close(self) -> None:
844
848
self .log_last_operation ('PassThruClose' )
845
849
846
850
def specific_send (self , payload : bytes , timeout : Optional [float ] = None ):
847
- if timeout is None :
848
- timeout = 0
849
- result = self .interface .PassThruWriteMsgs (self .channelID , payload , self .protocol .value , Timeout = int (timeout * 1000 ))
851
+ timeout = 0 if timeout is None else timeout
852
+
853
+ # Fix for avoid ERR_CONCURRENT_API_CALL. Stop reading
854
+ self .sem .acquire ()
855
+ self .result = self .interface .PassThruWriteMsgs (self .channelID , payload , self .protocol .value , Timeout = int (timeout * 1000 ))
856
+ self .log_last_operation ('PassThruWriteMsgs' , with_raise = True )
857
+ self .sem .release ()
850
858
851
859
def specific_wait_frame (self , timeout : Optional [float ] = None ) -> Optional [bytes ]:
852
860
if not self .opened :
0 commit comments