Answer the question
In order to leave comments, you need to log in
How to declare an array of structures in Python (cypyton)?
In general, the problem is this. There is a certain library that imports structures from the C library using ctypes.
The library is here python_j2534
In python, a structure class is created accordingly ...
import ctypes as ct
from J2534.dllLoader import MyDll
PassThru_Data = (ct.c_ubyte * 4128)
class PassThru_Msg(ct.Structure):
_fields_ = [
("ProtocolID", ct.c_ulong),
("RxStatus", ct.c_ulong),
("TxFlags", ct.c_ulong),
("Timestamp", ct.c_ulong),
("DataSize", ct.c_ulong),
("ExtraDataIndex",ct.c_ulong),
("Data", PassThru_Data)]
ptData = PassThru_Data
class baseMsg(PassThru_Msg):
def _setData(self, data):
print (data)
self.DataSize = len(data)
self.Data = ptData()
for i in range(self.DataSize):
self.Data[i] = data[i]
def setID(self, ID):
d = Func.IntToID(ID)
self._setData(d)
def setIDandData(self, ID, data = []):
d = Func.IntToID(ID) + data
self._setData(d)</spoiler>
class pt15765Msg(baseMsg):
def __init__(self, TxFlag):
self.ProtocolID = ProtocolID.ISO15765
self.TxFlags = TxFlag
class ptMskMsg(pt15765Msg):
pass
class ptPatternMsg(pt15765Msg):
pass
class ptFlowControlMsg(pt15765Msg):
pass
class ptTxMsg(baseMsg):
def __init__(self, ProtocolID, TxFlags):
self.ProtocolID = ProtocolID
self.TxFlags = TxFlags
class ptRxMsg(baseMsg):
def show(self):
print(self.ProtocolID, self.RxStatus, self.Data[:self.DataSize])
msg = J2534.ptRxMsg()
print(msg.Data[:100])
The PassThruWriteMsgs function is used to transmit network protocol messages over an existing logical
communication channel. The network protocol messages will flow from the User Application to the
PassThru device. long PassThruWriteMsgs( unsigned long ChannelID, PASSTHRU_MSG *pMsg, unsigned long *pNumMsgs, unsigned long Timeout );
Parameters
ChannelID
The logical communication channel identifier assigned by the J2534 API/DLL when the communication
channel was opened via the PassThruConnect function.
pMsg
Pointer to the message structure containing the UserApplication transmit message(s).
For sending more than one message, this must be a pointer to an array of PASSTHRU_MSG structures.
Refer to PASSTHRU_MSG structure definition on page 46.
PNumMsgs
Pointer to the variable that contains the number of PASSTHRU_MSG structures that are allocated for
transmit frames. On function completion this variable will contain the actual number of messages sent to
the vehicle network. The transmitted number of messages may be less than the number requested by the
UserApplication.
Timeout
Timeout interval(in milliseconds) to wait for transmit completion. A value of zero instructs the API/DLL
to queue as many transmit messages as possible and return immediately. A nonzero timeout value
instructs the API/DLL to wait for the timeout interval to expire before returning. The API/DLL will not
wait the entire timeout interval if an error occurs or the specified number of messages have been sent.
PASSTHRU_MSG Msg[2];
msg[0].Data[12]
print(msg.Data[:100])
print(msg[0].Data[:100])
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question