Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions udsoncan/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ def __init__(self, windll: str, rxid: int, txid: int, name: Optional[str] = None

def open(self) -> "J2534Connection":
self.exit_requested = False
self.sem = threading.Semaphore()
self.rxthread = threading.Thread(target=self.rxthread_task, daemon=True)
self.rxthread.start()
self.opened = True
Expand All @@ -812,13 +813,16 @@ def is_open(self) -> bool:

def rxthread_task(self) -> None:
while not self.exit_requested:
self.sem.acquire()
try:
result, data, numMessages = self.interface.PassThruReadMsgs(self.channelID, self.protocol.value, 1, 1)
if data is not None:
self.rxqueue.put(data)
except Exception:
self.logger.critical("Exiting J2534 rx thread")
self.exit_requested = True
self.sem.release()
time.sleep(0.001)

def log_last_operation(self, exec_method: str, with_raise = False) -> None:
if self.result != Error_ID.ERR_SUCCESS:
Expand All @@ -844,9 +848,13 @@ def close(self) -> None:
self.log_last_operation('PassThruClose')

def specific_send(self, payload: bytes, timeout: Optional[float] = None):
if timeout is None:
timeout = 0
result = self.interface.PassThruWriteMsgs(self.channelID, payload, self.protocol.value, Timeout=int(timeout * 1000))
timeout = 0 if timeout is None else timeout

# Fix for avoid ERR_CONCURRENT_API_CALL. Stop reading
self.sem.acquire()
self.result = self.interface.PassThruWriteMsgs(self.channelID, payload, self.protocol.value, Timeout=int(timeout * 1000))
self.log_last_operation('PassThruWriteMsgs', with_raise=True)
self.sem.release()

def specific_wait_frame(self, timeout: Optional[float] = None) -> Optional[bytes]:
if not self.opened:
Expand Down
2 changes: 1 addition & 1 deletion udsoncan/j2534.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def PassThruOpen(self, pDeviceID=None):
if not pDeviceID:
pDeviceID = ctypes.c_ulong()

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

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