Quantex GmbH
Your region: Europe

PassThruClose v4.04 v5.0

Terminating communication with the adapter

Last updated:

Description

The function terminates communication with the adapter and releases all associated resources. When it is called, all open channels (protocols) are closed automatically, so there is no need to call PassThruDisconnect() for each channel separately.

long PassThruClose(unsigned long DeviceID)
Important: Always call PassThruClose() before the program exits. If you do not, the next call to PassThruOpen() will return the error ERR_DEVICE_IN_USE.

Parameters

Return error codes

Code Description Possible causes and solutions
STATUS_NOERROR Function completed successfully -
ERR_INVALID_DEVICE_ID Invalid device identifier
  • DeviceID was not obtained from PassThruOpen()
  • The device had already been closed
  • Solution: make sure you pass a valid DeviceID
ERR_DEVICE_NOT_CONNECTED Connection to the adapter has been lost
  • The adapter was powered off or disconnected from the network
  • Solution: resources are released automatically, this can be ignored
ERR_FAILED Internal error
  • Failed to release resources
  • Solution: use PassThruGetLastError() for details

Examples

C/C++ example

#include "j2534_dll.hpp"

unsigned long DeviceID; // ID obtained from PassThruOpen

// ... working with the device ...

// Close the connection
long ret = PassThruClose(DeviceID);
if (ret != STATUS_NOERROR)
{
    char error[256];
    PassThruGetLastError(error);
    printf("Close error: %s\n", error);
}

Kotlin example (Android)

// deviceID obtained earlier from ptOpen
val result = j2534.ptClose(deviceID)

if (result.status == STATUS_NOERROR) {
    Log.i("J2534", "Connection to the adapter closed")
} else {
    Log.e("J2534", "Close error: ${result.status}")
}

Python example (ctypes)

from ctypes import *

# device_id obtained earlier from PassThruOpen

ret = j2534.PassThruClose(device_id)

if ret == 0:  # STATUS_NOERROR
    print("Connection closed")
else:
    error = create_string_buffer(256)
    j2534.PassThruGetLastError(error)
    print(f"Error: {error.value.decode()}")

C# example (P/Invoke)

// deviceId obtained earlier from PassThruOpen

int ret = J2534.PassThruClose(deviceId);

if (ret == 0) // STATUS_NOERROR
{
    Console.WriteLine("Connection closed");
}
else
{
    var error = new System.Text.StringBuilder(256);
    J2534.PassThruGetLastError(error);
    Console.WriteLine($"Error: {error}");
}