Skip to content

Commit ac54977

Browse files
authored
Fix J2534: ERR_CONCURRENT_API_CALL with using Pulsar (#250)
1 parent e9cfb13 commit ac54977

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

udsoncan/connections.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -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:

udsoncan/j2534.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def PassThruOpen(self, pDeviceID=None):
185185
if not pDeviceID:
186186
pDeviceID = ctypes.c_ulong()
187187

188-
result = dllPassThruOpen(ctypes.POINTER(ctypes.c_int)(), byref(pDeviceID))
188+
result = dllPassThruOpen(bytes('J2534-2:', 'ascii'), byref(pDeviceID))
189189
return Error_ID(hex(result)), pDeviceID
190190

191191
def PassThruConnect(self, deviceID, protocol, baudrate, pChannelID=None):

0 commit comments

Comments
 (0)