PyJ2534.dll

This module provides a Python-native implementation of the J2534-1 API.

Functions

get_interfaces()

Enumerate all registered J2534 04.04 Pass-Thru interface DLLs

load_interface(dll_path)

Load a J2534 DLL.

Classes

J2534Dll(dll_path)

Wrapper around a J2534-1 DLL.

PyJ2534.dll.get_interfaces()

Enumerate all registered J2534 04.04 Pass-Thru interface DLLs

Returns

A dict mapping display names of any registered J2534 Pass-Thru DLLs to their absolute filepath.

The name can be used in user-facing GUI elements to allow selection of a particular Pass-Thru device, and filepath can be passed to load_interface() to instantiate a J2534Dll wrapping the desired DLL.

Return type

dict

PyJ2534.dll.load_interface(dll_path)

Load a J2534 DLL.

Parameters

dll_path (str) – Absolute filepath to the DLL to load

Returns

A wrapper around the supplied DLL

Return type

J2534Dll

class PyJ2534.dll.J2534Dll(dll_path)

Wrapper around a J2534-1 DLL.

Refer to the J2534-1 API specification for more information.

All functions raise a J2534Error if an error occurs.

__init__(dll_path)

Instantiate a wrapper to the DLL at the given filepath.

PassThruOpen()

Open the Pass-Thru device.

Returns

Handle to the opened device

Return type

int

PassThruClose(device_id)

Close the Pass-Thru device

Parameters

device_id (int) – Handle to the previously opened device

PassThruConnect(device_id, protocol, flags, baud)

Establish a Pass-Thru connection using the given device.

Parameters
  • device_id (int) – Handle to the previously opened device

  • protocol (ProtocolID) – Desired protocol

  • flags (ProtocolFlags) – Connection flags

  • baud (int) – Desired baud rate

Returns

Handle to the opened channel

Return type

int

PassThruDisconnect(channel_id)

Close the specified Pass-Thru channel.

Parameters

channel_id (int) – Handle to the previously opened channel

PassThruReadMsgs(channel_id, num_msgs=1, timeout=None)

Read messages from the specified channel.

Parameters
  • channel_id (int) – Handle to the previously opened channel

  • num_msgs (int) – Number of messages to attempt to read.

  • timeout (int) –

    Read timeout in ms, or None.

    If None, then this function will return up to num_msgs from the receive buffer (or nothing) and return immediately.

    Otherwise, this function will return either when the timeout has expired, an error occurs, or the specified number of messages has been read.

Returns

list of PyJ2534.define.PASSTHRU_MSG instances.

If no timeout is specified, up to num_msgs messages from the receive buffer are returned immediately.

Otherwise, this function will return when num_msgs messages have been read from the receive buffer, or raises a timeout J2534Error if the timeout lapses before num_msgs messages have been read.

Return type

list

PassThruWriteMsgs(channel_id, msgs, timeout=None)

Write messages to the specified channel.

Returns the number of messages successfully transmitted (non-zero timeout) or queued (no timeout).

Parameters
  • channel_id (int) – Handle to the previously opened channel

  • msgs (list) – list of PASSTHRU_MSG instances

  • timeout (int) – Write timeout in ms, or None

Returns

Number of successfully transmitted/queued messages.

If no timeout is specified, the number of messages queued into the write buffer is returned immediately.

Otherwise, the number of transmitted messages is returned, or a timeout J2534Error is raised if the timeout lapses before all provided messages have been transmitted.

Return type

int

PassThruStartPeriodicMsg(channel_id, msg, interval)

Queue the specified message for periodic transmission.

Parameters
  • channel_id (int) – Handle to the previously opened channel

  • msg (PASSTHRU_MSG) – Message to be queued

  • interval (int) – Period of transmissions, in ms. Valid intervals are between 5-65535ms

Returns

Handle to the periodic message

Return type

int

PassThruStopPeriodicMsg(channel_id, msg_id)

Stop the transmission of the specified message

Parameters
  • channel_id (int) – Handle to the previously opened channel

  • msg_id (int) – Handle to the periodic message to stop

PassThruStartMsgFilter(channel_id, filter_type, mask_msg=None, pattern_msg=None, flow_msg=None)

Configure filtering for messages on the specified channel.

Keywords are to be specified as required. See the SAE J2534-1 recommended practices document for more information.

Parameters
  • channel_id (int) – Handle to the previously opened channel

  • filter_type (FilterType) – Type of filter

  • mask_msg (PASSTHRU_MSG) – Mask message

  • pattern_msg (PASSTHRU_MSG) – Pattern message

  • flow_msg (PASSTHRU_MSG) – ignored when filter_type is PASS_FILTER or BLOCK_FILTER

Returns

Handle to the created filter.

Return type

int

PassThruStopMsgFilter(channel_id, filter_id)

Remove the specified filter from the specified channel.

Parameters
  • channel_id (int) – Handle to the previously opened channel

  • filter_id (int) – Handle to the periodic message to stop

PassThruSetProgrammingVoltage(device_id, pin_number, voltage)

Set the programming voltage on the specified pin on the specified device.

Parameters
  • device_id (int) – Handle to the previously opened device

  • pin_number (ProgrammingPin) – Pin to set

  • voltage (int) – Voltage to apply to the pin. The voltage can either directly specified in mV, or via the ProgrammingVoltage enumeration for cases where it’s desired to switch off the voltage or short the pin to GND. Acceptable ranges are between 5000 and 20000.

PassThruReadVersion(device_id)

Get version information.

Parameters

device_id (int) – Handle to the previously opened device

Returns

3-tuple of versions: (device firmware, DLL, and API)

Return type

tuple

PassThruGetLastError()

Get the last error message generated by the interface.

Returns

Error message

Return type

str

PassThruIoctlGetConfig(channel_id, params)

Get protocol configuration parameters for the given channel.

Parameters
  • channel_id (int) – Handle to the previously opened channel

  • params (list) – list of IoctlParameter to retrieve values of

Returns

dict mapping the requested IoctlParameter to their currently set int values

Return type

dict

PassThruIoctlSetConfig(channel_id, params)

Set protocol configuration parameters for the given channel.

Parameters
  • channel_id (int) – Handle to the previously opened channel

  • params (dict) – Mapping of IoctlParameter to desired values

PassThruIoctlReadVbatt(device_id)

Read the voltage at pin 16 of the J1962 connector.

Parameters

device_id (int) – Handle to the previously opened device

Returns

Pin 16 voltage, in mV

Return type

int

PassThruIoctlReadProgVoltage(device_id)

Read the programming voltage of the Pass-Thru device.

Returns an int indicating the voltage in mV

Parameters

device_id (int) – Handle to the previously opened device

Returns

Programming voltage, in mV

Return type

int

PassThruIoctlFiveBaudInit(channel_id, addr)

Initiate a five-baud initialization.

Parameters
  • channel_id (int) – Handle to the previously opened channel

  • addr (int) – Target address for initialization

Returns

The response from the ECU

Return type

bytes

PassThruIoctlFastInit(channel_id, msg=None)

Initiate a fast initialization.

Parameters
  • channel_id (int) – Handle to the previously opened channel

  • msg (PASSTHRU_MSG) – Message to be sent to the ECU for initialization.

Returns

If a response is expected, a PASSTHRU_MSG containing the response from the ECU, None otherwise.

Return type

PASSTHRU_MSG

PassThruIoctlClearTxBuffer(channel_id)

Clear the transmit messages queue.

Parameters

channel_id (int) – Handle to the previously opened channel

PassThruIoctlClearRxBuffer(channel_id)

Clear the received messages queue.

Parameters

channel_id (int) – Handle to the previously opened channel

PassThruIoctlClearPeriodicMsgs(channel_id)

Clear all configured periodic messages.

Parameters

channel_id (int) – Handle to the previously opened channel

PassThruIoctlClearMsgFilters(channel_id)

Clear all configured filters.

Parameters

channel_id (int) – Handle to the previously opened channel

PassThruIoctlClearFunctMsgLookupTable(channel_id)

Clear the functional message look-up table.

Parameters

channel_id (int) – Handle to the previously opened channel

PassThruIoctlAddToFunctMsgLookupTable(channel_id, addrs)

Add addresses to the functional message look-up table.

Parameters
  • channel_id (int) – Handle to the previously opened channel

  • addrs (list) – list of int containing the addresses to be added

PassThruIoctlDeleteFromFunctMsgLookupTable(channel_id, addrs)

Delete addresses to the functional message look-up table

Parameters
  • channel_id (int) – Handle to the previously opened channel

  • addrs (list) – list of int containing the addresses to be deleted