Skip to content

Commit e9a4a4f

Browse files
authored
Fix j2534 connection params (#273)
* Allow to set J2534 - protocol and bauderate in constructor * J2534 - Allow to receive frames with padding error flag
1 parent 4f4b019 commit e9a4a4f

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

udsoncan/connections.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,10 @@ class J2534Connection(BaseConnection):
709709
:type name: string
710710
:param debug: This will enable windows debugging mode in the dll (see tactrix doc for additional information)
711711
:type debug: boolean
712-
:param args: Optional parameters list (Unused right now).
713-
:type args: list
714-
:param kwargs: Optional parameters dictionary Unused right now).
715-
:type kwargs: dict
712+
:param protocol: CAN protocol
713+
:type protocol: Protocol_ID
714+
:param baudrate: Operation bauderate
715+
:type baudrate: int
716716
717717
"""
718718

@@ -727,23 +727,29 @@ class J2534Connection(BaseConnection):
727727
exit_requested: bool
728728
opened: bool
729729

730-
def __init__(self, windll: str, rxid: int, txid: int, name: Optional[str] = None, debug: bool = False, *args, **kwargs):
730+
def __init__(self,
731+
windll: str,
732+
rxid: int,
733+
txid: int,
734+
name: Optional[str] = None,
735+
debug: bool = False,
736+
protocol = None,
737+
baudrate = 500000,
738+
):
731739
BaseConnection.__init__(self, name)
732740

733-
# Set up a J2534 interface using the DLL provided
734-
try:
735-
self.interface = J2534(windll=windll, rxid=rxid, txid=txid)
736-
except FileNotFoundError:
737-
raise RuntimeError('DLL not found')
738-
739-
# Set the protocol to ISO15765, Baud rate to 500000
740-
self.protocol = Protocol_ID.ISO15765
741-
self.baudrate = 500000
741+
self.protocol = protocol if protocol else Protocol_ID.ISO15765
742+
self.baudrate = baudrate
742743
self.debug = debug
743744

744745
try:
746+
# Set up a J2534 interface using the DLL provided
747+
self.interface = J2534(windll=windll, rxid=rxid, txid=txid)
748+
745749
# Open the interface (connect to the DLL)
746750
self.result, self.devID = self.interface.PassThruOpen()
751+
except FileNotFoundError:
752+
raise RuntimeError('DLL not found')
747753
except OSError as e:
748754
if e.errno in [0x16, 0xe06d7363]:
749755
raise RuntimeError('J2534 Device busy')
@@ -771,7 +777,7 @@ def __init__(self, windll: str, rxid: int, txid: int, name: Optional[str] = None
771777
self.log_last_operation("PassThruConnect", with_raise=True)
772778

773779
configs = SCONFIG_LIST([
774-
(Ioctl_ID.DATA_RATE.value, 500000),
780+
(Ioctl_ID.DATA_RATE.value, self.baudrate),
775781
(Ioctl_ID.LOOPBACK.value, 0),
776782
(Ioctl_ID.ISO15765_BS.value, 0x20),
777783
(Ioctl_ID.ISO15765_STMIN.value, 0),

udsoncan/j2534.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def PassThruReadMsgs(self, ChannelID, protocol, pNumMsgs=1, Timeout=100):
214214
result = dllPassThruReadMsgs(ChannelID, byref(pMsg), byref(pNumMsgs), c_ulong(Timeout))
215215
if Error_ID(hex(result)) == Error_ID.ERR_BUFFER_EMPTY or pNumMsgs == 0:
216216
return None, None, 0
217-
elif pMsg.RxStatus == 0 or pMsg.RxStatus == 0x100:
217+
elif pMsg.RxStatus in [0, 0x100, 0x110]:
218218
return Error_ID(hex(result)), bytes(pMsg.Data[4:pMsg.DataSize]), pNumMsgs
219219

220220
def PassThruWriteMsgs(self, ChannelID, Data, protocol, pNumMsgs=1, Timeout=1000):

0 commit comments

Comments
 (0)