Scan for devices
Last modified:
The function scans for available ScanDoc adapters and returns the number of devices found. This function is part of the SAE J2534-1 standard and is intended for device discovery before calling PassThruOpen().
long PassThruScanForDevices(unsigned long* pDeviceCount)
PassThruGetNextDevice() to retrieve information about each discovered device.
unsigned long variable allocated by the application. On successful return, the variable will contain the number of devices found.The function performs the following steps:
pDeviceCountPassThruGetNextDevice()PassThruScanForDevices() → Scan for available devices
↓
PassThruGetNextDevice() → Retrieve information about each device (call N times)
↓
PassThruOpen() → Open a connection to the selected device
↓
...
PassThruScanForDevices() is not mandatory. If the device name is known in advance, you can call
PassThruOpen() directly with the required connection parameters.
Network scan timeout: 2000 ms. BLE scan timeout: 3000 ms. Total execution time can be up to 5 seconds when Bluetooth is enabled.
| Code | Description | Possible causes and solutions |
|---|---|---|
| STATUS_NOERROR | Function completed successfully | The number of devices found has been written to pDeviceCount (may be 0) |
| ERR_NULL_PARAMETER | pDeviceCount pointer not provided | Pass a valid pointer to an unsigned long variable |
| ERR_CONCURRENT_API_CALL | A J2534 API function is already running |
|
| ERR_NOT_SUPPORTED | Function not supported |
|
| ERR_FAILED | Internal error |
|
#include "j2534_dll.hpp"
unsigned long deviceCount = 0;
// Scan for devices
long ret = PassThruScanForDevices(&deviceCount);
if (ret != STATUS_NOERROR)
{
char error[256];
PassThruGetLastError(error);
printf("Scan error: %s\n", error);
return;
}
printf("Devices found: %lu\n", deviceCount);
if (deviceCount == 0)
{
printf("No devices found\n");
return;
}
// Retrieve information about each device
SDEVICE deviceInfo;
for (unsigned long i = 0; i < deviceCount; i++)
{
ret = PassThruGetNextDevice(&deviceInfo);
if (ret == STATUS_NOERROR)
{
printf("Device %lu: %s\n", i + 1, deviceInfo.DeviceName);
}
}
val j2534 = J2534JNI(context)
// Scan for devices
val scanResult = j2534.ptScanForDevices()
if (scanResult.status == STATUS_NOERROR) {
Log.i("J2534", "Devices found: ${scanResult.deviceCount}")
// Retrieve information about each device
for (i in 0 until scanResult.deviceCount) {
val deviceInfo = j2534.ptGetNextDevice()
if (deviceInfo.status == STATUS_NOERROR) {
Log.i("J2534", "Device ${i + 1}: ${deviceInfo.deviceName}")
}
}
} else {
Log.e("J2534", "Scan error: ${scanResult.status}")
}
from ctypes import *
import platform
# Load the library
if platform.system() == "Windows":
j2534 = windll.LoadLibrary("j2534sd_v05_00_x64.dll")
elif platform.system() == "Darwin":
j2534 = cdll.LoadLibrary("libj2534_v05_00.dylib")
else:
j2534 = cdll.LoadLibrary("libj2534_v05_00.so")
device_count = c_ulong()
# Scan for devices
ret = j2534.PassThruScanForDevices(byref(device_count))
if ret == 0: # STATUS_NOERROR
print(f"Devices found: {device_count.value}")
# SDEVICE structure for retrieving device information
class SDEVICE(Structure):
_fields_ = [
("DeviceName", c_char * 80),
("DeviceAvailable", c_ulong),
("DeviceDLLFWStatus", c_ulong),
("DeviceConnectMedia", c_ulong),
("DeviceConnectSpeed", c_ulong),
("DeviceSignalQuality", c_ulong),
("DeviceSignalStrength", c_ulong)
]
# Retrieve information about each device
for i in range(device_count.value):
device_info = SDEVICE()
ret = j2534.PassThruGetNextDevice(byref(device_info))
if ret == 0:
print(f"Device {i + 1}: {device_info.DeviceName.decode()}")
else:
error = create_string_buffer(256)
j2534.PassThruGetLastError(error)
print(f"Error: {error.value.decode()}")
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct SDEVICE
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string DeviceName;
public uint DeviceAvailable;
public uint DeviceDLLFWStatus;
public uint DeviceConnectMedia;
public uint DeviceConnectSpeed;
public uint DeviceSignalQuality;
public uint DeviceSignalStrength;
}
class J2534
{
[DllImport("j2534sd_v05_00_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int PassThruScanForDevices(out uint pDeviceCount);
[DllImport("j2534sd_v05_00_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int PassThruGetNextDevice(out SDEVICE psDevice);
[DllImport("j2534sd_v05_00_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int PassThruGetLastError(
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pErrorDescription);
}
// Usage:
uint deviceCount;
int ret = J2534.PassThruScanForDevices(out deviceCount);
if (ret == 0) // STATUS_NOERROR
{
Console.WriteLine($"Devices found: {deviceCount}");
for (uint i = 0; i < deviceCount; i++)
{
SDEVICE deviceInfo;
ret = J2534.PassThruGetNextDevice(out deviceInfo);
if (ret == 0)
{
Console.WriteLine($"Device {i + 1}: {deviceInfo.DeviceName}");
}
}
}
else
{
var error = new System.Text.StringBuilder(256);
J2534.PassThruGetLastError(error);
Console.WriteLine($"Error: {error}");
}
PassThruGetNextDevice() - Retrieve information about discovered devicesPassThruOpen() - Establish communication with the adapter