Start a periodic message
Last updated:
Starts automatic periodic transmission of a message on the bus at a fixed interval. Used to keep a diagnostic session alive (Tester Present) or to poll sensors periodically.
long PassThruStartPeriodicMsg(unsigned long ChannelID, PASSTHRU_MSG* pMsg, unsigned long* pMsgID, unsigned long TimeInterval)
PassThruConnect.PassThruStopPeriodicMsg.| Code | Description | Possible causes and solutions |
|---|---|---|
| STATUS_NOERROR | Function completed successfully | — |
| ERR_NULL_PARAMETER | The pMsg pointer is not set |
|
| ERR_INVALID_MSG | Invalid message structure |
|
| ERR_INVALID_CHANNEL_ID | Invalid channel identifier |
|
| ERR_DEVICE_NOT_CONNECTED | No connection to the adapter |
|
| ERR_INVALID_DEVICE_ID | Invalid device identifier |
|
| ERR_INVALID_TIME_INTERVAL | Invalid time interval |
|
| ERR_NOT_SUPPORTED | The parameters are not supported by the adapter |
|
| ERR_MSG_PROTOCOL_ID | Protocol mismatch |
|
| ERR_EXCEEDED_LIMIT | Periodic message limit exceeded |
|
| ERR_FAILED | Internal error |
|
#include "j2534_lib.hpp"
unsigned long ChannelID; // channel ID
unsigned long MsgID; // ID for the new periodic message
long Ret;
PASSTHRU_MSG Msg;
// "Tester Present" message for ISO15765
Msg.ProtocolID = ISO15765;
Msg.TxFlags = ISO15765_FRAME_PAD;
Msg.DataSize = 5;
Msg.Data[0] = 0x00;
Msg.Data[1] = 0x00;
Msg.Data[2] = 0x07;
Msg.Data[3] = 0xDF; // ECU address
Msg.Data[4] = 0x3E; // Tester Present command
// Start transmission every 2000 ms
Ret = PassThruStartPeriodicMsg(ChannelID, &Msg, &MsgID, 2000);
if (Ret != STATUS_NOERROR)
{
// Error handling
}
// channelID obtained earlier
val timeInterval = 2000 // ms
// "Tester Present" message for ISO15765
val msg = PassThruMsg(
protocolID = ISO15765,
dataSize = 5,
txFlags = ISO15765_FRAME_PAD,
data = byteArrayOf(0x00, 0x00, 0x07, 0xDF.toByte(), 0x3E)
)
val result = j2534.ptStartPeriodicMsg(channelID, msg, timeInterval)
if (result.status == STATUS_NOERROR) {
val msgID = result.msgId
// Periodic message started successfully
Log.i("J2534", "Periodic message started, MsgID: $msgID")
} else {
// Error handling
Log.e("J2534", "Failed to start periodic message: ${result.status}")
}
import ctypes
# Load the library
j2534 = ctypes.CDLL("libj2534_v04_04.so") # Linux
# j2534 = ctypes.WinDLL("j2534sd_v04_04_x64.dll") # Windows
# channel_id obtained earlier
time_interval = 2000 # ms
# Message structure
class PASSTHRU_MSG(ctypes.Structure):
_fields_ = [
("ProtocolID", ctypes.c_ulong),
("RxStatus", ctypes.c_ulong),
("TxFlags", ctypes.c_ulong),
("Timestamp", ctypes.c_ulong),
("DataSize", ctypes.c_ulong),
("ExtraDataIndex", ctypes.c_ulong),
("Data", ctypes.c_ubyte * 4128)
]
msg = PASSTHRU_MSG()
msg.ProtocolID = 6 # ISO15765
msg.TxFlags = 0x40 # ISO15765_FRAME_PAD
msg.DataSize = 5
msg.Data[0:5] = [0x00, 0x00, 0x07, 0xDF, 0x3E] # Tester Present
msg_id = ctypes.c_ulong()
ret = j2534.PassThruStartPeriodicMsg(channel_id, ctypes.byref(msg), ctypes.byref(msg_id), time_interval)
if ret == 0: # STATUS_NOERROR
print(f"Periodic message started, MsgID: {msg_id.value}")
using System;
using System.Runtime.InteropServices;
// channel_id obtained earlier
uint timeInterval = 2000; // ms
var msg = new PASSTHRU_MSG
{
ProtocolID = 6, // ISO15765
TxFlags = 0x40, // ISO15765_FRAME_PAD
DataSize = 5,
Data = new byte[4128]
};
msg.Data[0] = 0x00;
msg.Data[1] = 0x00;
msg.Data[2] = 0x07;
msg.Data[3] = 0xDF;
msg.Data[4] = 0x3E; // Tester Present
uint msgId;
int ret = J2534.PassThruStartPeriodicMsg(channelId, ref msg, out msgId, timeInterval);
if (ret == 0) // STATUS_NOERROR
{
Console.WriteLine($"Periodic message started, MsgID: {msgId}");
}