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: Optional[asyncio.events.AbstractEventLoop] = None)[source]
Bases:
pycyphal.transport.can.media._media.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: Optional[asyncio.events.AbstractEventLoop] = 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.
- start(handler: Callable[[Sequence[Tuple[pycyphal.transport._timestamp.Timestamp, pycyphal.transport.can.media._frame.Envelope]]], None], no_automatic_retransmission: bool) None [source]
- configure_acceptance_filters(configuration: Sequence[pycyphal.transport.can.media._filter.FilterConfiguration]) None [source]
- async send(frames: Iterable[pycyphal.transport.can.media._frame.Envelope], monotonic_deadline: float) int [source]