MIO04 Quick-Start-Guide / SocketCAN Demo

SocketCAN Demo

In this demo, we’ll demonstrate how to receive data from a CAN bus and print it to the console. This demo is using the Linux SocketCAN framework.

WARNING This documentation assumes that ModuCop is your target. Users of other Linux machines: Please install our Open Source socketcan-io4edge solution on your target.

Prerequisites

Hardware

  • A Moducop that is in the same network as your MIO04
  • A development PC (Windows or Linux), connected via Network to the Moducop
  • CANbus with at least one CAN device
  • Cable to connect the CAN device with the MIO04

Bus Configuration

Bus Configuration must be set once to tell the MIO04 about the CAN parameters. This configuration is saved persistently in the device. You only need to perform this configuration step once, it survives reboots and power cycles.

In this example, we assume your

  • Bitrate is 125 kBit
  • Sampling Point is 0.625 (62.5%)
  • Synchronization Jump Width is 1
  • Listen only mode is off (i.e. Normal operation)

Configure the device. You specify a string that has the form bitrate:sampling-point/1000:sjw:listen-only

On your Moducop, run:

io4edge-cli -d MIO04-1 set-parameter can-config 125000:625:1:0
# Restart to apply parameters
io4edge-cli -d MIO04-1 restart

Alternatively, you can define the CAN configuration via the SERVICE interface and the config menu:

config> can-config 125000:625:1:0
config> reboot

Connecting

CAN Connection

Connect CAN_L, CAN_H and GND_ISO to the CAN bus. Be sure to have correct termination of 120R at each end of the line.

Create a socketCAN instance

To access the MIO04 via socketCAN, we create a virtual socketCAN network that matches the service name of your MIO04 CAN Interface.

The virtual socket CAN network must be named according to MIO04 CAN Interface service name. E.g. if the service name is MYDEV-can, the virtual socketCAN device must be named vcanMYDEV (without -can). Because network interface names can have only max. 15 characters, but service names can be longer, there is a rule to map longer service names to socketCAN device names:

vcan<first-4-chars-of-service-name>xx<last-5-chars-of-service-name>

Examples:

  • Service Name S101-IOU04-USB-EXT-1-can -> vcan name vcanS101xxEXT-1
  • Service Name 123456789012-can -> vcan name vcan1234xx89012
  • Service Name MIO04-1-can -> vcan name vcanMIO04-1

Now, create a virtual socketCAN network. On your Moducop, execute:

ip link add dev vcanMIO04-1 type vcan
ip link set up vcanMIO04-1

Function Test

Using the candump tool (part of can-utils package), you should see all frames that are sent on the CAN bus. Example (would dump also error information from CANbus):

./candump vcanMIO04-1 vcanMIO04-1,1FFFFFFF:1FFFFFFF,#FFFFFFFF -e
  vcanMIO04-1  6B6   [5]  37 67 2F 0F F2
  vcanMIO04-1  24A   [6]  B1 39 8A 3A A5 77
  vcanMIO04-1  57C   [5]  01 B2 9F 37 22
  vcanMIO04-1  665   [8]  1C C2 60 0A 8E E3 85 42
  vcanMIO04-1  18B   [5]  B0 E5 E4 2E 24
  vcanMIO04-1  0D0   [8]  64 49 45 71 6B B2 6E 09
  vcanMIO04-1  146   [7]  2E A6 CF 44 1A E9 2A
  vcanMIO04-1  508   [0]
  vcanMIO04-1  726   [8]  B0 B5 2E 62 70 89 78 4F
  vcanMIO04-1  454   [2]  15 01