pycyphal.transport.can.media.socketcan package

Module contents

The module is always importable but is functional only on GNU/Linux.

For testing or experimentation on a local machine it is often convenient to use a virtual CAN bus instead of a real one. Using SocketCAN, one can set up a virtual CAN bus interface as follows:

modprobe can
modprobe can_raw
modprobe vcan
ip link add dev vcan0 type vcan
ip link set vcan0 mtu 72         # Enable CAN FD by configuring the MTU of 64+8
ip link set up vcan0

Where vcan0 can be replaced with any other valid interface name. Please read the SocketCAN documentation for more information.

class pycyphal.transport.can.media.socketcan.SocketCANMedia(iface_name: str, mtu: int, loop: AbstractEventLoop | None = None)[source]

Bases: Media

This media implementation provides a simple interface for the standard Linux SocketCAN media layer. If you are testing with a virtual CAN bus and you need CAN FD, you may need to enable it manually (https://stackoverflow.com/questions/36568167/can-fd-support-for-virtual-can-vcan-on-socketcan); otherwise, you may observe errno 90 “Message too long”. Configuration example:

ip link set vcan0 mtu 72

SocketCAN documentation: https://www.kernel.org/doc/Documentation/networking/can.txt

__init__(iface_name: str, mtu: int, loop: AbstractEventLoop | None = None) None[source]

CAN Classic/FD is selected automatically based on the MTU. It is not possible to use CAN FD with MTU of 8 bytes.

Parameters:
  • iface_name – E.g., can0.

  • mtu – The maximum data field size in bytes. CAN FD is used if this value > 8, Classic CAN otherwise. This value must belong to Media.VALID_MTU_SET.

  • loop – Deprecated.

property interface_name: str[source]
property mtu: int[source]
property number_of_acceptance_filters: int[source]

512 for SocketCAN.

start(handler: Callable[[Sequence[Tuple[Timestamp, Envelope]]], None], no_automatic_retransmission: bool) None[source]
configure_acceptance_filters(configuration: Sequence[FilterConfiguration]) None[source]
async send(frames: Iterable[Envelope], monotonic_deadline: float) int[source]
close() None[source]
static list_available_interface_names() Iterable[str][source]