Skip to content

Setting up the host for CANopen

The connector reads and writes the bus through a SocketCAN interface of the device. You prepare this interface on the host (the device), outside logiccloud. The connector never changes the bit rate or the link state, because that needs the capability CAP_NET_ADMIN.

Package typeWhat the connector needsCANopen
Linux installation script (docker or podman)Host network, no extra capabilityYes, with linux-setup.sh --network host. With the default bridge network the container does not see can0.
Plain Linux (no container)Host network namespace, no capabilityYes. Unconfirmed: bind and send on a real interface, until the hardware test (LC-2307).
FLECSHost network for the instanceUnconfirmed
PLCnextHost network namespace of the controllerUnconfirmed on a device
uc-addon (u-OS)Host network option of the add-onUnconfirmed
Standard LXCcan0 as a phys interface, or the host namespaceUnconfirmed. The operator changes the LXC configuration.
insys LXCThe shipped configuration uses veth on br0No, until the configuration uses a phys interface
periMICAarm/v7No. There is no arm/v7 binary.
ctrlX snapStrict confinementUnconfirmed. Access to the CAN socket is not tested.
Cloud vPLC (vPlcType)No CAN interfaceNo. The installer skips the connector and logs a WARNING.
Kubernetes vPLCNo CAN interfaceNo. Same as the cloud vPLC.

Goal: a SocketCAN interface that is UP, runs at the bit rate of the bus and is visible to the connector.

Why a person is needed: the kernel configuration needs root, and only you know the bit rate of your bus.

Prerequisites:

  • Root access (or sudo) on the device.
  • A CAN adapter with a SocketCAN driver in the kernel.
  • The bit rate of the bus in bit/s, for example 250000. It must equal the Bit rate of the connection (250 kbit/s is 250000 bit/s).
  • Check: ip -details link show type can lists your interface, for example can0.

Steps:

  1. Load the kernel modules: sudo modprobe can && sudo modprobe can_raw. Expected: no output. Check with lsmod | grep '^can': the lines can_raw and can appear.

  2. Set the bit rate: sudo ip link set can0 down; sudo ip link set can0 type can bitrate 250000. Expected: no output.

  3. Bring the link up: sudo ip link set can0 up. Expected: no output.

  4. Check: ip -details link show can0. Expected: the output contains state UP and bitrate 250000.

  5. Make it permanent, so that the link is up after a reboot. Use one of these ways:

    • systemd-networkd: create /etc/systemd/network/80-can0.network with this content, then run sudo systemctl enable --now systemd-networkd.

      [Match]
      Name=can0
      [CAN]
      BitRate=250K
    • ifupdown: add this to /etc/network/interfaces:

      auto can0
      iface can0 inet manual
      pre-up ip link set can0 type can bitrate 250000
      up ip link set can0 up
      down ip link set can0 down

    Also load the modules at boot: write the two lines can and can_raw to /etc/modules-load.d/can.conf.

  6. Containers and LXC:

    • Linux installation script: run sudo bash linux-setup.sh --network host reinstall-container. The container keeps its data. Expected: Container reinstalled and running. Then check that the container sees the interface: sudo docker exec logiccloud ls /sys/class/net (with podman: sudo podman exec logiccloud ls /sys/class/net). Expected: can0 is in the list. See Layer 2 on a device installed with the Linux script for the effects of the host network (ports 8080, 42010 and 42011 are used directly; only one logiccloud container per device).
    • LXC: set lxc.net.0.type = phys and lxc.net.0.link = can0 in the container configuration, then restart the container.

If a step fails:

  • RTNETLINK answers: Operation not supported: the kernel has no driver for the adapter. Install the driver or use another adapter.
  • RTNETLINK answers: Device or resource busy: the link is already up. Run sudo ip link set can0 down first, then repeat step 2.
  • The interface is missing in ip link: the adapter is not detected. Check dmesg | tail -n 30 for the driver messages.

Final check: after you deploy a runtime with a CANopen connection, ps aux | grep canopen-connector on the device shows a process with canopen-connector --config .../canopen.json. Without a runtime, check that ip -details link show can0 shows state UP and the bit rate.

What to report if you ask for help: the output of ip -details link show can0, the package type, and the log of the canopen-connector process.

You can test a connection without hardware on a virtual CAN interface:

  1. sudo modprobe vcan
  2. sudo ip link add dev vcan0 type vcan
  3. sudo ip link set vcan0 up

Enter vcan0 as CAN interface. A vcan interface has no bit rate, and the connector accepts it for any Bit rate.