Quantex GmbH
DE RU EN EL
Your region: Europe

PassThruScanForDevices v5.0

Scan for devices

Last modified:

Description

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)
Note: After calling this function, use PassThruGetNextDevice() to retrieve information about each discovered device.

Parameters

How it works

The function performs the following steps:

  1. Scans for available ScanDoc devices on the local network (LAN/WiFi)
  2. If Bluetooth is enabled, scans for BLE devices
  3. Writes the number of devices found to pDeviceCount
  4. Stores the device list for later retrieval via PassThruGetNextDevice()

Function call order

PassThruScanForDevices()  → Scan for available devices
    ↓
PassThruGetNextDevice()   → Retrieve information about each device (call N times)
    ↓
PassThruOpen()            → Open a connection to the selected device
    ↓
...
Important: Calling PassThruScanForDevices() is not mandatory. If the device name is known in advance, you can call PassThruOpen() directly with the required connection parameters.

Timeouts

Network scan timeout: 2000 ms. BLE scan timeout: 3000 ms. Total execution time can be up to 5 seconds when Bluetooth is enabled.

Returned error codes

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
  • Another J2534 function has not yet completed
  • Solution: wait for the previous call to complete
ERR_NOT_SUPPORTED Function not supported
  • The DLL does not support dynamic device scanning
  • Solution: call PassThruOpen() directly with known parameters
ERR_FAILED Internal error
  • Network interface error
  • Bluetooth initialization error
  • Solution: use PassThruGetLastError() to obtain details

Examples

C/C++ example

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

Kotlin example (Android)

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

Python example (ctypes)

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

C# example (P/Invoke)

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

Related functions