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 (int) – id used for transmission

  • is_fd (bool) – should the Bus be initialized in CAN-FD mode

  • enable_brs (bool) – sets the bitrate_switch flag to use higher transmission speed

  • can_filters (list) – iterable used to filter can id on reception

  • is_extended_id (bool) – this flag controls the size of the arbitration_id field

  • receive_own_messages (bool) – if set transmitted messages will be received

  • logging_activated (bool) – boolean used to enable logfile creation

  • log_path (str) – trace directory path (absolute or relative)

  • log_name (str) – trace full name (without file extension)

_cc_close()[source]

Close the current can bus channel and close the log handler.

Return type:

None

_cc_open()[source]

Open a can bus channel, set filters for reception and activate

Return type:

None

_cc_receive(timeout=0.0001)[source]

Receive a can message using configured filters.

Parameters:

timeout (float) – timeout applied on reception

Return type:

Dict[str, Union[bytes, int]]

Returns:

tuple containing the received data and the source can id

_cc_send(msg, remote_id=None, **kwargs)[source]

Send a CAN message at the configured id. If remote_id parameter is not given take configured ones

Parameters:
  • msg (Union[Message, bytes]) – data to send

  • remote_id (Optional[int]) – destination can id used

Return type:

None

pykiso.lib.connectors.cc_socket_can.cc_socket_can.os_name()[source]

Returns the system/OS name.

Return type:

str

Returns:

os name such as ‘Linux’, ‘Darwin’, ‘Java’, ‘Windows’