@@ -795,6 +795,7 @@ def __init__(self, windll: str, rxid: int, txid: int, name: Optional[str] = None
795795
796796 def open (self ) -> "J2534Connection" :
797797 self .exit_requested = False
798+ self .sem = threading .Semaphore ()
798799 self .rxthread = threading .Thread (target = self .rxthread_task , daemon = True )
799800 self .rxthread .start ()
800801 self .opened = True
@@ -812,13 +813,16 @@ def is_open(self) -> bool:
812813
813814 def rxthread_task (self ) -> None :
814815 while not self .exit_requested :
816+ self .sem .acquire ()
815817 try :
816818 result , data , numMessages = self .interface .PassThruReadMsgs (self .channelID , self .protocol .value , 1 , 1 )
817819 if data is not None :
818820 self .rxqueue .put (data )
819821 except Exception :
820822 self .logger .critical ("Exiting J2534 rx thread" )
821823 self .exit_requested = True
824+ self .sem .release ()
825+ time .sleep (0.001 )
822826
823827 def log_last_operation (self , exec_method : str , with_raise = False ) -> None :
824828 if self .result != Error_ID .ERR_SUCCESS :
@@ -844,9 +848,13 @@ def close(self) -> None:
844848 self .log_last_operation ('PassThruClose' )
845849
846850 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 ()
850858
851859 def specific_wait_frame (self , timeout : Optional [float ] = None ) -> Optional [bytes ]:
852860 if not self .opened :
0 commit comments