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
3 changes: 2 additions & 1 deletion udsoncan/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ def __init__(self,
windll: str,
rxid: int,
txid: int,
extid: Optional[int] = None,
name: Optional[str] = None,
debug: bool = False,
protocol = None,
Expand All @@ -713,7 +714,7 @@ def __init__(self,

try:
# Set up a J2534 interface using the DLL provided
self.interface = J2534(windll=windll, rxid=rxid, txid=txid)
self.interface = J2534(windll=windll, rxid=rxid, txid=txid, extid=extid)

# Open the interface (connect to the DLL)
self.result, self.devID = self.interface.PassThruOpen()
Expand Down
48 changes: 24 additions & 24 deletions udsoncan/j2534.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ class PASSTHRU_MSG(Structure):
("ExtraDataIndex", c_ulong),
("Data", ctypes.c_ubyte * 4128)]

def setData(self, data: bytes):
self.DataSize = len(data)
for i in range(self.DataSize):
self.Data[i] = data[i]

def getData(self):
addr_size = 5 if self.RxStatus & RxStatus.ISO15765_ADDR_TYPE.value else 4
return bytes(self.Data[addr_size : self.DataSize])


class SCONFIG(Structure):
_fields_ = [("Parameter", c_ulong),
Expand Down Expand Up @@ -44,7 +53,7 @@ class J2534():
dllPassThruStartMsgFilter = None
dllPassThruIoctl = None

def __init__(self, windll, rxid, txid):
def __init__(self, windll, rxid, txid, extid):
global dllPassThruOpen
global dllPassThruClose
global dllPassThruConnect
Expand All @@ -68,6 +77,11 @@ def __init__(self, windll, rxid, txid):
self.txFlags |= TxFlags.CAN_29_BIT_ID.value
self.connectFlags |= ConnectFlags.CAN_29_BIT_ID.value

if extid is not None:
self.rxid += extid.to_bytes(1, 'big')
self.txid += extid.to_bytes(1, 'big')
self.txFlags |= TxFlags.ISO15765_ADDR_TYPE.value

self.logger = logging.getLogger()

dllPassThruOpenProto = WINFUNCTYPE(
Expand Down Expand Up @@ -221,30 +235,24 @@ def PassThruReadMsgs(self, ChannelID, protocol, pNumMsgs=1, Timeout=20):
if pMsg.RxStatus & (RxStatus.TX_INDICATION.value | RxStatus.TX_MSG_TYPE.value | RxStatus.START_OF_MESSAGE.value):
continue

return Error_ID(hex(result)), bytes(pMsg.Data[4:pMsg.DataSize]), pNumMsgs
return Error_ID(hex(result)), pMsg.getData(), pNumMsgs

def PassThruWriteMsgs(self, ChannelID, Data, protocol, pNumMsgs=1, Timeout=1000):
txmsg = PASSTHRU_MSG()
txmsg.TxFlags = self.txFlags
txmsg.ProtocolID = protocol

Data = self.txid + Data
self.logger.info("Sending data: " + str(Data.hex()))

for i in range(0, len(Data)):
txmsg.Data[i] = Data[i]

txmsg.DataSize = len(Data)
txmsg = PASSTHRU_MSG()
txmsg.TxFlags = self.txFlags
txmsg.ProtocolID = protocol
txmsg.setData(Data)

result = dllPassThruWriteMsgs(ChannelID, byref(txmsg), byref(c_ulong(pNumMsgs)), c_ulong(Timeout))

return Error_ID(hex(result))

def PassThruStartPeriodicMsg(self, ChannelID, Data, MsgID=0, TimeInterval=100):
pMsg = PASSTHRU_MSG()

pMsg.Data = Data
pMsg.DataSize = len(Data)
pMsg.setData(Data)

result = dllPassThruStartPeriodicMsg(ChannelID, byref(pMsg), byref(c_ulong(MsgID)), c_ulong(TimeInterval))

Expand Down Expand Up @@ -281,18 +289,14 @@ def PassThruStartMsgFilter(self, ChannelID, protocol):
msgMask = PASSTHRU_MSG()
msgMask.ProtocolID = protocol
msgMask.TxFlags = self.txFlags
msgMask.DataSize = 4
msgMask.RxStatus = msgMask.ExtraDataIndex = 0xCCCC_CCCC
for i in range(0, 4):
msgMask.Data[i] = 0xFF
msgMask.setData(b'\xFF' * len(self.rxid))

msgPattern = PASSTHRU_MSG()
msgPattern.ProtocolID = protocol
msgPattern.TxFlags = self.txFlags
msgPattern.DataSize = 4
msgPattern.RxStatus = msgPattern.ExtraDataIndex = 0xCCCC_CCCC
for i in range(0, len(self.rxid)):
msgPattern.Data[i] = self.rxid[i]
msgPattern.setData(self.rxid)

if protocol in [Protocol_ID.ISO9141.value, Protocol_ID.ISO14230.value]:
filterType = c_ulong(Filter.PASS_FILTER.value)
Expand All @@ -302,10 +306,8 @@ def PassThruStartMsgFilter(self, ChannelID, protocol):
msgFlow = PASSTHRU_MSG()
msgFlow.ProtocolID = protocol
msgFlow.TxFlags = self.txFlags
msgFlow.DataSize = 4
msgFlow.RxStatus = msgFlow.ExtraDataIndex = 0xCCCC_CCCC
for i in range(0, len(self.txid)):
msgFlow.Data[i] = self.txid[i]
msgFlow.setData(self.txid)
msgFlow = byref(msgFlow)

msgID = c_ulong(0)
Expand Down Expand Up @@ -455,8 +457,6 @@ class RxStatus(Enum):
START_OF_MESSAGE = 0x00000002
ISO15765_FIRST_FRAME = 0x00000002

ISO15765_EXT_ADDR = 0x00000080

# 0 = No break received
# 1 = Break received
RX_BREAK = 0x00000004
Expand Down