uds.transport_interface.can_transport_interface

Definition and implementation of UDS Transport Interface for CAN bus.

Module Contents

Classes

AbstractCanTransportInterface

Abstract definition of Transport Interface for managing UDS on CAN bus.

PyCanTransportInterface

Transport Interface for managing UDS on CAN with python-can package as bus handler.

class uds.transport_interface.can_transport_interface.AbstractCanTransportInterface(can_bus_manager, addressing_information, **kwargs)[source]

Bases: uds.transport_interface.abstract_transport_interface.AbstractTransportInterface

Inheritance diagram of uds.transport_interface.can_transport_interface.AbstractCanTransportInterface

Abstract definition of Transport Interface for managing UDS on CAN bus.

CAN Transport Interfaces are meant to handle UDS middle layers (Transport and Network) on CAN bus.

Create Transport Interface (an object for handling UDS Transport and Network layers).

Parameters:
  • can_bus_manager (Any) – An object that handles CAN bus (Physical and Data layers of OSI Model).

  • addressing_information (uds.can.AbstractCanAddressingInformation) – Addressing Information of CAN Transport Interface.

  • kwargs (Any) –

    Optional arguments that are specific for CAN bus.

    • parameter n_as_timeout:

      Timeout value for N_As time parameter.

    • parameter n_ar_timeout:

      Timeout value for N_Ar time parameter.

    • parameter n_bs_timeout:

      Timeout value for N_Bs time parameter.

    • parameter n_br:

      Value of N_Br time parameter to use in communication.

    • parameter n_cs:

      Value of N_Cs time parameter to use in communication.

    • parameter n_cr_timeout:

      Timeout value for N_Cr time parameter.

    • parameter dlc:

      Base CAN DLC value to use for CAN Packets.

    • parameter use_data_optimization:

      Information whether to use CAN Frame Data Optimization.

    • parameter filler_byte:

      Filler byte value to use for CAN Frame Data Padding.

Raises:

TypeError – Provided Addressing Information value has unexpected type.

property segmenter: uds.segmentation.CanSegmenter

Value of the segmenter used by this CAN Transport Interface.

Return type:

uds.segmentation.CanSegmenter

property n_as_timeout: uds.utilities.TimeMillisecondsAlias

Timeout value for N_As time parameter.

Return type:

uds.utilities.TimeMillisecondsAlias

abstract property n_as_measured: uds.utilities.TimeMillisecondsAlias | None

Get the last measured value of N_As time parameter.

Returns:

Time in milliseconds or None if the value was never measured.

Return type:

Optional[uds.utilities.TimeMillisecondsAlias]

property n_ar_timeout: uds.utilities.TimeMillisecondsAlias

Timeout value for N_Ar time parameter.

Return type:

uds.utilities.TimeMillisecondsAlias

abstract property n_ar_measured: uds.utilities.TimeMillisecondsAlias | None

Get the last measured value of N_Ar time parameter.

Returns:

Time in milliseconds or None if the value was never measured.

Return type:

Optional[uds.utilities.TimeMillisecondsAlias]

property n_bs_timeout: uds.utilities.TimeMillisecondsAlias

Timeout value for N_Bs time parameter.

Return type:

uds.utilities.TimeMillisecondsAlias

abstract property n_bs_measured: uds.utilities.TimeMillisecondsAlias | None

Get the last measured value of N_Bs time parameter.

Returns:

Time in milliseconds or None if the value was never measured.

Return type:

Optional[uds.utilities.TimeMillisecondsAlias]

property n_br: uds.utilities.TimeMillisecondsAlias

Get the value of N_Br time parameter which is currently set.

Note

The actual (observed on the bus) value will be slightly longer as it also includes computation and CAN Interface delays.

Return type:

uds.utilities.TimeMillisecondsAlias

property n_br_max: uds.utilities.TimeMillisecondsAlias

Get the maximum valid value of N_Br time parameter.

Warning

To assess maximal value of N_Br, the actual value of N_Ar time parameter is required. Either the latest measured value of N_Ar would be used, or 0ms would be assumed (if there are no measurement result).

Return type:

uds.utilities.TimeMillisecondsAlias

property n_cs: uds.utilities.TimeMillisecondsAlias | None

Get the value of N_Cs time parameter which is currently set.

Note

The actual (observed on the bus) value will be slightly longer as it also includes computation and CAN Interface delays.

Return type:

Optional[uds.utilities.TimeMillisecondsAlias]

property n_cs_max: uds.utilities.TimeMillisecondsAlias

Get the maximum valid value of N_Cs time parameter.

Warning

To assess maximal value of N_Cs, the actual value of N_As time parameter is required. Either the latest measured value of N_Ar would be used, or 0ms would be assumed (if there are no measurement result).

Return type:

uds.utilities.TimeMillisecondsAlias

property n_cr_timeout: uds.utilities.TimeMillisecondsAlias

Timeout value for N_Cr time parameter.

Return type:

uds.utilities.TimeMillisecondsAlias

abstract property n_cr_measured: uds.utilities.TimeMillisecondsAlias | None

Get the last measured value of N_Cr time parameter.

Returns:

Time in milliseconds or None if the value was never measured.

Return type:

Optional[uds.utilities.TimeMillisecondsAlias]

property addressing_information: uds.can.AbstractCanAddressingInformation

Addressing Information of Transport Interface.

Warning

Once the value is set, it must not be changed as it might cause communication problems.

Return type:

uds.can.AbstractCanAddressingInformation

property dlc: int

Value of base CAN DLC to use for output CAN Packets.

Note

All output CAN Packets will have this DLC value set unless CAN Frame Data Optimization is used.

Return type:

int

property use_data_optimization: bool

Information whether to use CAN Frame Data Optimization during CAN Packets creation.

Return type:

bool

property filler_byte: int

Filler byte value to use for output CAN Frame Data Padding during segmentation.

Return type:

int

N_AS_TIMEOUT: uds.utilities.TimeMillisecondsAlias = 1000

Timeout value of N_As time parameter according to ISO 15765-2.

N_AR_TIMEOUT: uds.utilities.TimeMillisecondsAlias = 1000

Timeout value of N_Ar time parameter according to ISO 15765-2.

N_BS_TIMEOUT: uds.utilities.TimeMillisecondsAlias = 1000

Timeout value of N_Bs time parameter according to ISO 15765-2.

N_CR_TIMEOUT: uds.utilities.TimeMillisecondsAlias = 1000

Timeout value of N_Cr time parameter according to ISO 15765-2.

DEFAULT_N_BR: uds.utilities.TimeMillisecondsAlias = 0

Default value of N_Br time parameter.

DEFAULT_N_CS: uds.utilities.TimeMillisecondsAlias | None

Default value of N_Cs time parameter.

class uds.transport_interface.can_transport_interface.PyCanTransportInterface(can_bus_manager, addressing_information, **kwargs)[source]

Bases: AbstractCanTransportInterface

Inheritance diagram of uds.transport_interface.can_transport_interface.PyCanTransportInterface

Transport Interface for managing UDS on CAN with python-can package as bus handler.

Note

Documentation for python-can package: https://python-can.readthedocs.io/

Create python-can Transport Interface.

Parameters:
  • can_bus_manager (can.BusABC) –

    Python-can bus object for handling CAN.

    Warning

    Bus must have capability of receiving transmitted frames (receive_own_messages=True set).

  • addressing_information (uds.can.AbstractCanAddressingInformation) – Addressing Information of CAN Transport Interface.

  • kwargs (Any) –

    Optional arguments that are specific for CAN bus.

    • parameter n_as_timeout:

      Timeout value for N_As time parameter.

    • parameter n_ar_timeout:

      Timeout value for N_Ar time parameter.

    • parameter n_bs_timeout:

      Timeout value for N_Bs time parameter.

    • parameter n_br:

      Value of N_Br time parameter to use in communication.

    • parameter n_cs:

      Value of N_Cs time parameter to use in communication.

    • parameter n_cr_timeout:

      Timeout value for N_Cr time parameter.

    • parameter dlc:

      Base CAN DLC value to use for CAN Packets.

    • parameter use_data_optimization:

      Information whether to use CAN Frame Data Optimization.

    • parameter filler_byte:

      Filler byte value to use for CAN Frame Data Padding.

property n_as_measured: uds.utilities.TimeMillisecondsAlias | None

Get the last measured value of N_As time parameter.

Returns:

Time in milliseconds or None if the value was never measured.

Return type:

Optional[uds.utilities.TimeMillisecondsAlias]

property n_ar_measured: uds.utilities.TimeMillisecondsAlias | None

Get the last measured value of N_Ar time parameter.

Returns:

Time in milliseconds or None if the value was never measured.

Return type:

Optional[uds.utilities.TimeMillisecondsAlias]

property n_bs_measured: uds.utilities.TimeMillisecondsAlias | None

Get the last measured value of N_Bs time parameter.

Returns:

Time in milliseconds or None if the value was never measured.

Return type:

Optional[uds.utilities.TimeMillisecondsAlias]

property n_cr_measured: uds.utilities.TimeMillisecondsAlias | None

Get the last measured value of N_Cr time parameter.

Returns:

Time in milliseconds or None if the value was never measured.

Return type:

Optional[uds.utilities.TimeMillisecondsAlias]

_MAX_LISTENER_TIMEOUT: float = 4280000.0

Maximal timeout value accepted by python-can listeners.

_MIN_NOTIFIER_TIMEOUT: float = 1e-07

Minimal timeout for notifiers that does not cause malfunctioning of listeners.

__del__()[source]

Safely close all threads open by this object.

_teardown_notifier(suppress_warning=False)[source]

Stop and remove CAN frame notifier for synchronous communication.

Parameters:

suppress_warning (bool) – Do not warn about mixing Synchronous and Asynchronous implementation.

Return type:

None

_teardown_async_notifier(suppress_warning=False)[source]

Stop and remove CAN frame notifier for asynchronous communication.

Parameters:

suppress_warning (bool) – Do not warn about mixing Synchronous and Asynchronous implementation.

Return type:

None

_setup_notifier()[source]

Configure CAN frame notifier for synchronous communication.

Return type:

None

_setup_async_notifier(loop)[source]

Configure CAN frame notifier for asynchronous communication.

Parameters:

loop (asyncio.AbstractEventLoop) – An asyncio event loop to use.

Return type:

None

clear_frames_buffers()[source]

Clear buffers with transmitted and received frames.

Warning

This will cause that all CAN packets received in a past are no longer accessible.

Return type:

None

static is_supported_bus_manager(bus_manager)[source]

Check whether provided value is a bus manager that is supported by this Transport Interface.

Parameters:

bus_manager (Any) – Value to check.

Returns:

True if provided bus object is compatible with this Transport Interface, False otherwise.

Return type:

bool

send_packet(packet)[source]

Transmit CAN packet.

Warning

Must not be called within an asynchronous function.

Parameters:

packet (uds.packet.CanPacket) – CAN packet to send.

Returns:

Record with historic information about transmitted CAN packet.

Return type:

uds.packet.CanPacketRecord

receive_packet(timeout=None)[source]

Receive CAN packet.

Warning

Must not be called within an asynchronous function.

Parameters:

timeout (Optional[uds.utilities.TimeMillisecondsAlias]) – Maximal time (in milliseconds) to wait.

Raises:
  • TypeError – Provided timeout value is not None neither int nor float type.

  • ValueError – Provided timeout value is less or equal 0.

  • TimeoutError – Timeout was reached.

Returns:

Record with historic information about received CAN packet.

Return type:

uds.packet.CanPacketRecord

async async_send_packet(packet, loop=None)[source]

Transmit CAN packet.

Parameters:
  • packet (uds.packet.CanPacket) – CAN packet to send.

  • loop (Optional[asyncio.AbstractEventLoop]) – An asyncio event loop used for observing messages.

Raises:

TypeError – Provided packet is not CAN Packet.

Returns:

Record with historic information about transmitted CAN packet.

Return type:

uds.packet.CanPacketRecord

async async_receive_packet(timeout=None, loop=None)[source]

Receive CAN packet.

Parameters:
  • timeout (Optional[uds.utilities.TimeMillisecondsAlias]) – Maximal time (in milliseconds) to wait.

  • loop (Optional[asyncio.AbstractEventLoop]) – An asyncio event loop used for observing messages.

Raises:
  • TypeError – Provided timeout value is not None neither int nor float type.

  • ValueError – Provided timeout value is less or equal 0.

  • TimeoutError – Timeout was reached.

Returns:

Record with historic information about received CAN packet.

Return type:

uds.packet.CanPacketRecord