IOU06 Quick-Start-Guide / CAN API Demo

CAN Demo using Io4Edge API

In this demo, we’ll demonstrate how to receive data from a CAN bus and print it to the console. This demo directly accesses the IOU06 CAN interface via the Io4Edge API.

Warning On the IOU06, the CAN and COM ports cannot be used at the same time. To enable CAN, set a persistent bus configuration. If you want to use the COM ports, remove the persistent bus configuration.

Prerequisites

Hardware

  • A Moducop Edge Computer with a IOU06 installed
  • 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 IOU06

Tools on Development PC

The examples are written in programming language Go, we download the go sources and compile them. Therefore we need some tools on your development PC:

Get Demo Software

Clone the repository containing the examples to a folder of your choise (here myworkdir)

c:
cd \myworkdir
git clone https://github.com/ci4rail/io4edge-client-go.git
cd io4edge-client-go
cd ~/myworkdir
git clone https://github.com/ci4rail/io4edge-client-go.git
cd io4edge-client-go

Bus Configuration

Bus Configuration must be set once to tell the IOU06 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 S101-IOU06-USB-EXT-1 set-parameter can-config 125000:625:1:0
# Restart to apply parameters
io4edge-cli -d S101-IOU06-USB-EXT-1 restart

Connecting (Rev. 0)

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.

Connecting (Rev. 1)

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.

Demo Software

Compile Demo

Run this in a powershell console

cd examples\canL2\streamDump
$Env:GOOS = "linux"
$Env:GOARCH = "arm64"
go build
cd examples/canL2/streamDump
GOOS=linux GOARCH=arm64 go build

This produces the binary file streamDump in the current folder.

Copy Demo to Moducop

Transfer the compiled binary. Replace <target-ip> with the IP address of your Moducop.

We copy the binary to the /data folder of ModuCop, as this is a writeable, whereas the rest of the filesystem is write protected.

scp streamDump root@<target-ip>:/data

Running the Demo

Login into your Moducop over SSH:

ssh root@<target-ip>

Once logged in into the Moducop’s Shell, run the demo.

In case your IOU06 is not in the slot next to the CPU, use a different address, e.g. S101-IOU06-USB-EXT-2-

/data/streamDump S101-IOU06-USB-EXT-1-can

Now you should see all frames that are sent on the CAN bus. Example:

Started stream
got stream data with 3 samples
  @56036918665 us: ID:7ff DATA:22 33 44  ERROR:CAN_NO_ERROR STATE:CAN_OK
  @56037270984 us: ID:123 DATA:22 33 44  ERROR:CAN_NO_ERROR STATE:CAN_OK
  @56037462740 us: ID:456 DATA:22 33 44  ERROR:CAN_NO_ERROR STATE:CAN_OK
got stream data with 3 samples
  @56038232385 us: ID:222 DATA:22 33 44  ERROR:CAN_NO_ERROR STATE:CAN_OK
  @56038422757 us: ID:334 DATA:22 33 44  ERROR:CAN_NO_ERROR STATE:CAN_OK
  @56038632969 us: ID:555 DATA:22 33 44  ERROR:CAN_NO_ERROR STATE:CAN_OK
...