Quantex GmbH
Your region: Europe

PassThruWriteMsgs v4.04

Sending messages

Last updated:

Description

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)
Important: For the ISO 15765 protocol, you must set up a Flow Control filter using PassThruStartMsgFilter before transmitting messages. Without it, the function returns the error ERR_NO_FLOW_CONTROL.

Parameters

Return error codes

Code Description Possible causes and solutions
STATUS_NOERROR Function completed successfully
ERR_DEVICE_NOT_CONNECTED No connection to the adapter
  • The adapter is turned off or the connection has been lost
  • Solution: Check the adapter power and the network/BLE connection
  • The IP address is set incorrectly
  • Solution: Check the connection parameters in PassThruOpen
ERR_INVALID_CHANNEL_ID A non-existent ChannelID channel identifier was specified
  • ChannelID was not obtained from PassThruConnect
  • Solution: Use the ChannelID returned by PassThruConnect
  • The channel was closed via PassThruDisconnect
  • Solution: Reopen the channel via PassThruConnect
ERR_NULL_PARAMETER The pMsg or pNumMsgs pointer is not set
  • NULL was passed instead of a pointer
  • Solution: Pass a valid pointer to the message array and to the count variable
ERR_TIMEOUT Not all messages could be transmitted within the specified time
  • Too many messages or too short a timeout
  • Solution: Increase the Timeout value or reduce the number of messages
  • Bus problems (no CAN acknowledgement)
  • Solution: Check the connection to the vehicle and the bus state
ERR_INVALID_MSG Invalid message structure in pMsg
  • Incorrect message data or size
  • Solution: Check the DataSize, Data and TxFlags fields in the PASSTHRU_MSG structure
ERR_MSG_PROTOCOL_ID The protocol in the message does not match the channel protocol
  • ProtocolID in the message structure differs from the one specified in PassThruConnect
  • Solution: Set pMsg->ProtocolID to the same protocol that was used when opening the channel
ERR_NO_FLOW_CONTROL No Flow Control filter is set for the ISO 15765 protocol
  • Attempt to transmit an ISO 15765 message without a configured filter
  • Solution: Call PassThruStartMsgFilter with the FLOW_CONTROL_FILTER type before transmitting
ERR_BUFFER_FULL The transmit queue is full
  • Too many messages in the queue (limit: 50 messages, 64 KB)
  • Solution: Wait for the previous messages to be sent or clear the queue via PassThruIoctl(CLEAR_TX_BUFFER)
ERR_FAILED Internal error in the library or adapter
  • Memory allocation error or stack failure
  • Solution: Call PassThruGetLastError() to get details

Examples

C/C++ example

#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
}

Kotlin example (Android)

// 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}")
}

Python example

# 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}")

C# example

// 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}");
}