Quantex GmbH
Your region: Europe

PassThruConnect v4.04 v5.0

Establishing a connection over a protocol

Last updated:

Description

The function establishes a connection over the specified protocol. The adapter supports two independent diagnostic lines. Each protocol is bound to its own line. Line 1 is connected to pins 6 and 14 of the OBD connector, and only the ISO15765 and CAN protocols can be connected to it. Line 2 is switchable, and the remaining protocols can be connected to it. Because the lines are independent, two protocols may operate at the same time. For example, ISO15765 and ISO14230, or ISO15765 and ISO15765_PS. The PS suffix means that the protocol can be switched onto the pins of the OBD connector.
The ISO15765 and CAN protocols, as well as ISO15765_PS and CAN_PS, can operate on the same physical line at the same time. This means you can initialize up to 4 protocols simultaneously in a single adapter. Note that the baud rates set for each pair of protocols must be identical. For example, ISO15765 and CAN at 500 Kbit on pins 6 and 14 of the OBD connector, and ISO15765_PS and CAN_PS at 125 Kbit on pins 3 and 11.

long PassThruConnect(unsigned long DeviceID, unsigned long ProtocolID, unsigned long Flags, unsigned long BaudRate, unsigned long *pChannelID)

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 has no power
  • Solution: Check the adapter's power and indicators
  • No network connection
  • Solution: Check the network cable or the WLAN connection
  • Incorrect IP address
  • Solution: Make sure the IP address is specified correctly in the connection string
ERR_INVALID_DEVICE_ID A non-existent adapter identifier DeviceID was specified
  • DeviceID was not obtained from PassThruOpen
  • Solution: First call PassThruOpen to obtain a valid DeviceID
  • The device was closed earlier
  • Solution: Verify that PassThruClose was not called for this device
ERR_NOT_SUPPORTED The protocol is not supported by the adapter
  • SCI protocols are not supported
  • Solution: Use supported protocols: CAN, ISO15765, ISO9141, ISO14230, etc.
  • Incompatible protocols (for example, VPW and PWM at the same time)
  • Solution: Use compatible protocol combinations
ERR_INVALID_PROTOCOL_ID v4.04
ERR_PROTOCOL_ID_NOT_SUPPORTED v5.0
A non-existent ProtocolID was specified
  • An invalid ProtocolID value was passed
  • Solution: Use the constants from j2534.h (ISO15765, CAN, ISO14230, etc.)
ERR_NULL_PARAMETER The pChannelID pointer is not specified
  • NULL was passed instead of a pointer to pChannelID
  • Solution: Pass a valid pointer to an unsigned long variable
ERR_INVALID_FLAGS v4.04
ERR_FLAG_NOT_SUPPORTED v5.0
An unsupported flag was specified
  • An invalid or incompatible flag was passed for this protocol
  • Solution: Check the flag combination. For ISO15765 use CAN_29BIT_ID or CAN_ID_BOTH
ERR_BAUDRATE_NOT_SUPPORTED An unsupported baud rate was specified
  • The baud rate is not supported for this protocol
  • Solution: For CAN use standard baud rates: 125000, 250000, 500000, 1000000
  • Solution: For K-Line use baud rates from 5 to 115200 bit/s
ERR_CHANNEL_IN_USE The channel is already in use
  • Defined by the J2534 standard
Important: In practice this error code will never appear, because on a repeated call to PassThruConnect, PassThruDisconnect is invoked automatically and the channel is reopened.
ERR_FAILED Internal error
  • Error in the DLL or in the adapter firmware
  • Solution: Call PassThruGetLastError() for a detailed description
  • Solution: Restart the adapter and try again

Examples

C/C++ example

#include "j2534_dll.hpp"

// DeviceID obtained earlier from PassThruOpen
unsigned long DeviceID;
unsigned long ChannelID;
unsigned long Flags = 0; // Depends on the protocol

// Connection over the CAN bus ISO 15765 at 500 Kbit/s
long ret = PassThruConnect(DeviceID, ISO15765, Flags, 500000, &ChannelID);
if (ret != STATUS_NOERROR)
{
    char error[256];
    PassThruGetLastError(error);
    // Error handling
}

Kotlin example (Android)

// deviceID obtained earlier from ptOpen
val protocolID = ISO15765
val flags = 0
val baudRate = 500000

val resConnect = j2534.ptConnect(deviceID, protocolID, flags, baudRate)
if (resConnect.status == STATUS_NOERROR) {
    val channelID = resConnect.chnlId
    // Communication channel with the vehicle is open
    Log.i("J2534", "Channel open, ChannelID: $channelID")
} else {
    // Error handling
    Log.e("J2534", "Error opening channel: ${resConnect.status}")
}

Python example

import ctypes

# Loading the library
# Windows: j2534 = ctypes.WinDLL("j2534sd_v04_04_x64.dll")
# macOS: j2534 = ctypes.CDLL("libj2534_v04_04.dylib")
# Linux: j2534 = ctypes.CDLL("libj2534_v04_04.so")

ISO15765 = 6
STATUS_NOERROR = 0

# device_id obtained earlier from PassThruOpen
device_id = ctypes.c_ulong(0)
channel_id = ctypes.c_ulong()
protocol_id = ISO15765
flags = 0
baud_rate = 500000

ret = j2534.PassThruConnect(device_id, protocol_id, flags, baud_rate, ctypes.byref(channel_id))
if ret == STATUS_NOERROR:
    print(f"Channel open, ChannelID: {channel_id.value}")
else:
    error_msg = ctypes.create_string_buffer(256)
    j2534.PassThruGetLastError(error_msg)
    print(f"Error: {error_msg.value.decode()}")

C# example

using System;
using System.Runtime.InteropServices;

public class J2534Example
{
    // Windows: j2534sd_v04_04_x64.dll
    [DllImport("j2534sd_v04_04_x64.dll")]
    public static extern int PassThruConnect(uint deviceId, uint protocolId,
        uint flags, uint baudRate, out uint channelId);

    [DllImport("j2534sd_v04_04_x64.dll")]
    public static extern int PassThruGetLastError(byte[] errorMsg);

    const uint ISO15765 = 6;
    const int STATUS_NOERROR = 0;

    public void ConnectExample(uint deviceId)
    {
        uint channelId;
        uint flags = 0;
        uint baudRate = 500000;

        int ret = PassThruConnect(deviceId, ISO15765, flags, baudRate, out channelId);
        if (ret == STATUS_NOERROR)
        {
            Console.WriteLine($"Channel open, ChannelID: {channelId}");
        }
        else
        {
            byte[] errorMsg = new byte[256];
            PassThruGetLastError(errorMsg);
            Console.WriteLine($"Error: {System.Text.Encoding.ASCII.GetString(errorMsg)}");
        }
    }
}