Queue messages on a channel for transmission
Last updated:
The function places messages into the transmit queue of the pass-thru device for the specified channel.
On success, STATUS_NOERROR is returned, and the value pointed to by pNumMsgs
is updated to contain the actual number of messages that were queued.
PassThruWriteMsgs,
which was used in previous versions of the SAE J2534 API (v04.04).
long PassThruQueueMsgs(
unsigned long ChannelID,
PASSTHRU_MSG *pMsg,
unsigned long *pNumMsgs
)
pMsg are not modifiedPassThruStartPeriodicMsg)ISO 15765 logical channels may queue a single frame whose network address or
TxFlags do not match the RemoteAddress or RemoteTxFlags
specified when the channel was created.
ERR_MSG_NOT_ALLOWED.
Input parameter. The identifier of the physical or logical communication channel obtained from a call to
PassThruConnect() or PassThruLogicalConnect().
Input parameter. A pointer to an application-allocated array of PASSTHRU_MSG structures
containing the messages to queue.
Input/output parameter. A pointer to an unsigned long variable:
| Code | Description |
|---|---|
| STATUS_NOERROR | Function completed successfully. All messages were queued. |
| ERR_CONCURRENT_API_CALL | A J2534 API function was called before the previous call completed |
| ERR_DEVICE_NOT_OPEN | PassThruOpen() has not been successfully called |
| ERR_INVALID_CHANNEL_ID | Invalid ChannelID value |
| ERR_DEVICE_NOT_CONNECTED | Communication error with the pass-thru device. The device has been disconnected. |
| ERR_NOT_SUPPORTED | The device does not support this function for the given ChannelID |
| ERR_NULL_PARAMETER | pMsg or pNumMsgs is NULL |
| ERR_MSG_PROTOCOL_ID | The ProtocolID in the PASSTHRU_MSG structure does not match the channel's ProtocolID |
| ERR_INVALID_MSG | The message structure is invalid for the given ChannelID |
| ERR_MSG_NOT_ALLOWED | Attempt to queue a segmented message whose address/flags do not match the parameters of the ISO 15765 logical channel |
| ERR_BUFFER_FULL | The transmit queue is full. pNumMsgs contains the number of messages that were actually queued. |
| ERR_FAILED | Undefined error. Use PassThruGetLastError() to get a description. |
#include "j2534_dll.hpp"
unsigned long channelID = ...; // Channel ID from PassThruConnect/PassThruLogicalConnect
// Prepare the message
PASSTHRU_MSG msg = {0};
msg.ProtocolID = ISO15765;
msg.TxFlags = ISO15765_FRAME_PAD;
// Data: UDS Read Data By Identifier request (0x22)
unsigned char data[] = {0x00, 0x00, 0x07, 0xDF, 0x22, 0xF1, 0x90};
memcpy(msg.Data, data, sizeof(data));
msg.DataSize = sizeof(data);
unsigned long numMsgs = 1;
// Queue the message
long ret = PassThruQueueMsgs(channelID, &msg, &numMsgs);
if (ret == STATUS_NOERROR) {
printf("Messages queued: %lu\n", numMsgs);
} else if (ret == ERR_BUFFER_FULL) {
printf("Queue is full, messages queued: %lu\n", numMsgs);
} else {
char error[256];
PassThruGetLastError(error);
printf("Error: %s\n", error);
}
from ctypes import *
j2534 = cdll.LoadLibrary("libj2534_v05_00.dylib")
# PASSTHRU_MSG structure
class PASSTHRU_MSG(Structure):
_fields_ = [
("ProtocolID", c_ulong),
("RxStatus", c_ulong),
("TxFlags", c_ulong),
("Timestamp", c_ulong),
("DataSize", c_ulong),
("ExtraDataIndex", c_ulong),
("Data", c_ubyte * 4128)
]
channel_id = c_ulong(...) # Channel ID
# Prepare the message
msg = PASSTHRU_MSG()
msg.ProtocolID = 0x06 # ISO15765
msg.TxFlags = 0x40 # ISO15765_FRAME_PAD
# UDS Read Data By Identifier request
data = bytes([0x00, 0x00, 0x07, 0xDF, 0x22, 0xF1, 0x90])
for i, b in enumerate(data):
msg.Data[i] = b
msg.DataSize = len(data)
num_msgs = c_ulong(1)
# Queue the message
ret = j2534.PassThruQueueMsgs(channel_id, byref(msg), byref(num_msgs))
if ret == 0: # STATUS_NOERROR
print(f"Messages queued: {num_msgs.value}")
elif ret == 0x11: # ERR_BUFFER_FULL
print(f"Queue is full, queued: {num_msgs.value}")
else:
error = create_string_buffer(256)
j2534.PassThruGetLastError(error)
print(f"Error: {error.value.decode()}")
| Characteristic | PassThruWriteMsgs (v04.04) | PassThruQueueMsgs (v05.00) |
|---|---|---|
| Behavior | Blocking call with timeout | Non-blocking, immediate return |
| Timeout parameter | Yes | No |
| Logical channel support | No | Yes |
PassThruReadMsgs() - Read messages from a channelPassThruStartPeriodicMsg() - Start a periodic message (higher priority)PassThruSelect() - Select channels for monitoringPassThruLogicalConnect() - Create a logical channel