Establishing a connection over a protocol
Last updated:
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)
| Definition | pins | Description |
|---|---|---|
| J1850VPW | 2 VPW | Defined by the SAE J1850 and SAE J2178 standards. Can operate simultaneously with CAN and ISO15765. Not compatible with switchable protocols. |
| J1850PWM | 2, 10 PWM | Defined by the SAE J1850 standard. Can operate simultaneously with CAN and ISO15765. Not compatible with switchable protocols. |
| ISO9141 | 7K,15L Line | Defined by the ISO 9141 and SAE J1979 standards. Can operate simultaneously with CAN and ISO15765. Not compatible with switchable protocols. |
| ISO14230 | 7K,15L Line | |
| CAN | 6H,14L CAN | Raw CAN stream. Can operate simultaneously with all protocols. |
| ISO15765 | 6H,14L CAN | Defined by the ISO 15765-4 and ISO 14229-1 UDS standards. Can operate simultaneously with all protocols. |
| ISO15765_PS | Switchable CAN | Switchable version of ISO 15765. Can operate simultaneously with CAN and ISO15765. |
| ISO13400_PS Quantex | Ethernet | DoIP (Diagnostics over IP) — diagnostics over Ethernet per the ISO 13400 standard. For details, see the DoIP description. |
| For the full list of protocols, see the SAE J2534-1 standard. | ||
| Constant name | bit | Description |
|---|---|---|
| ISO9141_K_LINE | 12 | Use of the L line for protocol initialization. 0 = The L line and the K line are used for initialization 1 = Only the K line is used for initialization |
| CAN_29BIT_ID | 8 | CAN identifier type for the CAN and ISO 15765 protocols 0 = Packets with an 11-bit identifier are accepted. 1 = Packets with a 29-bit identifier are accepted. |
| For the full list of flags, see the SAE J2534-1 standard. | ||
| Code | Description | Possible causes and solutions |
|---|---|---|
| STATUS_NOERROR | Function completed successfully | — |
| ERR_DEVICE_NOT_CONNECTED | No connection to the adapter |
|
| ERR_INVALID_DEVICE_ID | A non-existent adapter identifier DeviceID was specified |
|
| ERR_NOT_SUPPORTED | The protocol is not supported by the adapter |
|
| ERR_INVALID_PROTOCOL_ID v4.04 ERR_PROTOCOL_ID_NOT_SUPPORTED v5.0 |
A non-existent ProtocolID was specified |
|
| ERR_NULL_PARAMETER | The pChannelID pointer is not specified |
|
| ERR_INVALID_FLAGS v4.04 ERR_FLAG_NOT_SUPPORTED v5.0 |
An unsupported flag was specified |
|
| ERR_BAUDRATE_NOT_SUPPORTED | An unsupported baud rate was specified |
|
| ERR_CHANNEL_IN_USE | The channel is already in use |
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 |
|
#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
}
// 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}")
}
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()}")
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)}");
}
}
}