IOU04 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 IOU04 CAN interface via the Io4Edge API.

Prerequisites

Hardware

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

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

Determine the Service Address of your IOU04

Io4Edge Devices are usually addressed by their service address, which is a name in the network.

The IOU04’s service name depends on the ModuCop’s slot and is usually S101-IOU04-USB-EXT-<slot-number>[-<function>], i.e. if the IOU04 is in the slot next to ModuCops CPU01, we have the following service names:

Service Name Description
S101-IOU04-USB-EXT-1 Core function
S101-IOU04-USB-EXT-1-com1 COM1
S101-IOU04-USB-EXT-1-com2 COM2
S101-IOU04-USB-EXT-1-can CAN

If you are unsure, you can also browse the available devices:

ssh root@<moducop-ip>

Once logged in into the Moducop Shell:

io4edge-cli scan -f

If your IOU04 is in the slot next to the CPU, the output should be:

S101-IOU04-USB-EXT-1, 192.168.201.1, S101-IOU04, <serial-number>
+---------------------+---------------------------+-------+
|    SERVICE TYPE     |       SERVICE NAME        | PORT  |
+---------------------+---------------------------+-------+
| _ttynvt._tcp        | S101-IOU04-USB-EXT-1-com1 | 10000 |
| _ttynvt._tcp        | S101-IOU04-USB-EXT-1-com2 | 10001 |
| _io4edge_canL2._tcp | S101-IOU04-USB-EXT-1-can  | 10002 |
+---------------------+---------------------------+-------+

Bus Configuration

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

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.

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 IOU04 is not in the slot next to the CPU, use a different address, e.g. S101-IOU04-USB-EXT-2-

/data/streamDump S101-IOU04-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
...

Updated: