Quantex GmbH
Your region: Europe

PassThruStartPeriodicMsg v4.04 v5.0

Start a periodic message

Last updated:

Description

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)

Parameters

Return error codes

Code Description Possible causes and solutions
STATUS_NOERROR Function completed successfully
ERR_NULL_PARAMETER The pMsg pointer is not set
  • nullptr was passed instead of a pointer to the message
  • Solution: pass a valid pointer to a PASSTHRU_MSG structure
ERR_INVALID_MSG Invalid message structure
  • The data size is 0 or exceeds 12 bytes
  • Solution: make sure DataSize is in the range 1–12
ERR_INVALID_CHANNEL_ID Invalid channel identifier
  • The channel was not opened or has already been closed
  • Solution: use the ChannelID obtained from PassThruConnect
ERR_DEVICE_NOT_CONNECTED No connection to the adapter
  • The adapter is powered off, the network was lost, or the IP address is incorrect
  • Solution: check the adapter power and the network connection
ERR_INVALID_DEVICE_ID Invalid device identifier
  • The DeviceID was not obtained through PassThruOpen or the device is closed
  • Solution: use the DeviceID obtained from PassThruOpen
ERR_INVALID_TIME_INTERVAL Invalid time interval
  • The TimeInterval value is outside the range 5–65535 ms
  • Solution: use an interval within the valid range
ERR_NOT_SUPPORTED The parameters are not supported by the adapter
  • An interval below 20 ms is not supported by the firmware
  • Solution: increase TimeInterval to 20 ms or higher
ERR_MSG_PROTOCOL_ID Protocol mismatch
  • The ProtocolID in the message does not match the channel protocol
  • Solution: set pMsg->ProtocolID to the same protocol specified in PassThruConnect
ERR_EXCEEDED_LIMIT Periodic message limit exceeded
  • The adapter supports a limited number of periodic messages (typically 10)
  • Solution: stop unused periodic messages via PassThruStopPeriodicMsg
ERR_FAILED Internal error
  • An error in the DLL or the adapter firmware
  • Solution: call PassThruGetLastError() for details

Examples

C/C++ example

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

Kotlin example (Android)

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

Python example

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

C# example

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