10. cc_socket_can
10.1. Setup SocketCAN
To use the socketCAN connector you have to make sure that your can socket has been initialized correctly.
sudo ip link set can0 up type can bitrate 500000 sample-point 0.75 dbitrate 2000000 dsample-point 0.8 fd on
sudo ip link set up can0
Make sure that ifconfig shows a socket can interface. Example shows can0 as available interface:
ifconfig
# outputs->
can0: flags=193<UP,RUNNING,NOARP> mtu 72
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 1000 (UNSPEC)
RX packets 30 bytes 90 (90.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 30 bytes 90 (90.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Warning
SocketCAN is only available under Linux.
10.1.1. Can Communication Channel SocketCAN
- module
cc_socket_can
- synopsis
CChannel implementation for CAN(fd) using SocketCAN
- class pykiso.lib.connectors.cc_socket_can.cc_socket_can.CCSocketCan(channel='vcan0', remote_id=None, is_fd=True, enable_brs=False, can_filters=None, is_extended_id=False, receive_own_messages=False, logging_activated=False, log_path=None, log_name=None, **kwargs)[source]
CAN FD channel-adapter.
Initialize can channel settings.
- Parameters
channel (
str
) – the can interface name. (i.e. vcan0, can1, ..)remote_id (
Optional
[int
]) – id used for transmissionis_fd (
bool
) – should the Bus be initialized in CAN-FD modeenable_brs (
bool
) – sets the bitrate_switch flag to use higher transmission speedcan_filters (
Optional
[list
]) – iterable used to filter can id on receptionis_extended_id (
bool
) – this flag controls the size of the arbitration_id fieldreceive_own_messages (
bool
) – if set transmitted messages will be receivedlogging_activated (
bool
) – boolean used to enable logfile creationlog_path (
Optional
[str
]) – trace directory path (absolute or relative)log_name (
Optional
[str
]) – trace full name (without file extension)