Sending messages
Last updated:
The function transmits messages over the diagnostic protocol. The adapter's transmit queue holds 50 messages per queue for a single channel and provides 64 KB of free memory for all queues. When a queue or all free memory is full, acceptance of new messages into the transmit queue is suspended.
long PassThruWriteMsg(unsigned long ChannelID, PASSTHRU_MSG *pMsg, unsigned long *pNumMsgs, unsigned long Timeout)
PassThruStartMsgFilter before transmitting messages. Without it, the function returns the error ERR_NO_FLOW_CONTROL.
PassThruConnect command.ERR_TIMEOUT is returned. If the timeout is
0, the messages are placed into the transmit queue without waiting for physical transmission, and the function returns immediately. In this case the ERR_TIMEOUT error is not generated.| Code | Description | Possible causes and solutions |
|---|---|---|
| STATUS_NOERROR | Function completed successfully | — |
| ERR_DEVICE_NOT_CONNECTED | No connection to the adapter |
|
| ERR_INVALID_CHANNEL_ID | A non-existent ChannelID channel identifier was specified |
|
| ERR_NULL_PARAMETER | The pMsg or pNumMsgs pointer is not set |
|
| ERR_TIMEOUT | Not all messages could be transmitted within the specified time |
|
| ERR_INVALID_MSG | Invalid message structure in pMsg |
|
| ERR_MSG_PROTOCOL_ID | The protocol in the message does not match the channel protocol |
|
| ERR_NO_FLOW_CONTROL | No Flow Control filter is set for the ISO 15765 protocol |
|
| ERR_BUFFER_FULL | The transmit queue is full |
|
| ERR_FAILED | Internal error in the library or adapter |
|
#include "j2534_dll.hpp"
// ChannelID obtained earlier from PassThruConnect
unsigned long ChannelID;
PASSTHRU_MSG Msg;
unsigned long NumMsgs = 1;
unsigned long Timeout = 200;
// Building an ISO 15765 message (request SID 0x22, PID 0xF190)
Msg.ProtocolID = ISO15765;
Msg.TxFlags = ISO15765_FRAME_PAD;
Msg.Data[0] = 0x00;
Msg.Data[1] = 0x00;
Msg.Data[2] = 0x07;
Msg.Data[3] = 0xDF;
Msg.Data[4] = 0x22;
Msg.Data[5] = 0xF1;
Msg.Data[6] = 0x90;
Msg.DataSize = 7;
long ret = PassThruWriteMsg(ChannelID, &Msg, &NumMsgs, Timeout);
if (ret != STATUS_NOERROR) {
char error[256];
PassThruGetLastError(error);
// Error handling
}
// channelID obtained earlier from ptConnect
val msg = PassThruMsg(
protocolID = ISO15765,
dataSize = 7,
txFlags = ISO15765_FRAME_PAD,
// VIN request (SID 0x22, PID 0xF190)
data = byteArrayOf(0x00, 0x00, 0x07, 0xDF.toByte(), 0x22, 0xF1.toByte(), 0x90.toByte())
)
val messages = arrayOf(msg)
val timeout = 200 // ms
val result = j2534.ptWriteMsgs(channelID, messages, timeout)
if (result.status == STATUS_NOERROR) {
Log.i("J2534", "Messages sent: ${result.numMsgs}")
} else {
Log.e("J2534", "Send error: ${result.status}")
}
# channel_id obtained earlier from PassThruConnect
msg = PassThruMsg()
msg.ProtocolID = ISO15765
msg.TxFlags = ISO15765_FRAME_PAD
msg.Data = bytes([0x00, 0x00, 0x07, 0xDF, 0x22, 0xF1, 0x90])
msg.DataSize = 7
num_msgs = ctypes.c_ulong(1)
timeout = 200 # ms
ret = j2534.PassThruWriteMsg(channel_id, ctypes.byref(msg), ctypes.byref(num_msgs), timeout)
if ret == 0: # STATUS_NOERROR
print(f"Messages sent: {num_msgs.value}")
else:
print(f"Send error: {ret}")
// channelId obtained earlier from PassThruConnect
var msg = new PassThruMsg {
ProtocolID = ISO15765,
TxFlags = ISO15765_FRAME_PAD,
Data = new byte[] { 0x00, 0x00, 0x07, 0xDF, 0x22, 0xF1, 0x90 },
DataSize = 7
};
uint numMsgs = 1;
uint timeout = 200; // ms
int ret = J2534.PassThruWriteMsg(channelId, ref msg, ref numMsgs, timeout);
if (ret == 0) {
Console.WriteLine($"Messages sent: {numMsgs}");
} else {
Console.WriteLine($"Send error: {ret}");
}