IOU03 Quick-Start-Guide

In this quick-start guide we will run demo programs that dump the frames on the MVB and CAN bus IOU03 to the console.

Prerequisites

Hardware

  • A Moducop Edge Computer with a IOU03 installed
  • A development PC (Windows or Linux), connected via Network to the Moducop

For MVB Demo:

  • MVB bus with at least a Master and a Slave

For CAN Demo:

  • CANbus with at least two CAN devices
  • Cable to connect the CAN device with the IOU03

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 IOU03

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

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

Service Name Description
S101-IOU03-USB-EXT-1 Core function
S101-IOU03-USB-EXT-1-mvbSniffer MVB function
S101-IOU03-USB-EXT-1-can CAN function

We need this service address in the demo programs to address the module, for example S101-IOU03-USB-EXT-1-mvbSniffer.

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 IOU03 is in the slot next to the CPU, the output should be:

S101-IOU03-USB-EXT-1, 192.168.201.1, S103-IOU01, <serial-number>
+-----------------------------+---------------------------------+-------+
|        SERVICE TYPE         |            SERVICE NAME         | PORT  |
+-----------------------------+---------------------------------+-------+
| _io4edge_mvbSniffer._tcp    | S101-IOU03-USB-EXT-1-mvbSniffer | 10000 |
| _io4edge_canL2._tcp         | S101-IOU03-USB-EXT-1-can        | 10001 |
+-----------------------------+---------------------------------+-------+

MVB Demo with Simulated Frames

The MVB loop demo will use the IOU03 internal MVB frame generator to simulate frames on the MVB, you don’t need to connect anything to the MVB connectors. The generated frames do not leave the IOU03. They are internally looped back in the IOU03.

The demo then dumps the simulated received frames to the console.

Demo Software

Compile Demo

Run this in a powershell console

cd examples\mvbSniffer\stream
$Env:GOOS = "linux"
$Env:GOARCH = "arm64"
go build
cd examples/mvbSniffer/stream
GOOS=linux GOARCH=arm64 go build

This produces the binary file stream 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 stream 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 IOU03 is not in the slot next to the CPU, use a different address, e.g. S101-IOU03-USB-EXT-2--mvbSniffer

/data/stream -gen S101-IOU03-USB-EXT-1-mvbSniffer

You should see an output like this:

Started stream
dt=0 addr=000123, kProcessData32Bit, data=01 02 03 04
dt=288 addr=000456, kProcessData16Bit, data=aa bb
dt=877 addr=000123, kProcessData32Bit, data=01 02 03 04
dt=288 addr=000456, kProcessData16Bit, data=aa bb
dt=877 addr=000123, kProcessData32Bit, data=01 02 03 04
dt=288 addr=000456, kProcessData16Bit, data=aa bb
dt=877 addr=000123, kProcessData32Bit, data=01 02 03 04
dt=288 addr=000456, kProcessData16Bit, data=aa bb
...

Receive from a Real MVB

To receive frames from the MVB, connect the IOU03 to a real MVB. The MVB bus is connected to the IOU03 via the two connectors labelled MVB1 and MVB2.

Connecting

MVB may be EMD or ESD. Depending on the position of the IOU03 in the bus, connect it like in the following drawing:

Connection for Binary I/O Demo

Demo Software

Run the same demo software as in the previous section, but don’t specify the -gen flag.

/data/stream S101-IOU03-USB-EXT-1-mvbSniffer

Then the tool should dump all telegrams on the bus to the console.

CAN Demo using the 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 IOU03 CAN interface via the Io4Edge API.

Bus Configuration

Bus Configuration must be set once to tell the IOU03 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 62.5%
  • Synchronization Jump Width is 1
  • Listen only mode is on (because the IOU03 can’t send)

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

Warning Always set the listen-only flag to 1 on the IOU03. Otherwise the device may try to send ACKs on the bus and this might result in incorrect behavior also on the receiver side.

On your Moducop, run:

io4edge-cli -d S101-IOU03-USB-EXT-1 set-parameter can-config 125000:625:1:1

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

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

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.

First, configure the bus parameters as described here.

Create a socketCAN instance

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

The virtual socket CAN network must be named according to IOU03 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 MIO03-1-can -> vcan name vcanMIO03-1

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

ip link add dev vcanS101xxEXT-1 type vcan
ip link set up vcanS101xxEXT-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 vcanS101xxEXT-1 vcanS101xxEXT-1,1FFFFFFF:1FFFFFFF,#FFFFFFFF -e
  vcanS101xxEXT-1  6B6   [5]  37 67 2F 0F F2
  vcanS101xxEXT-1  24A   [6]  B1 39 8A 3A A5 77
  vcanS101xxEXT-1  57C   [5]  01 B2 9F 37 22
  vcanS101xxEXT-1  665   [8]  1C C2 60 0A 8E E3 85 42
  vcanS101xxEXT-1  18B   [5]  B0 E5 E4 2E 24
  vcanS101xxEXT-1  0D0   [8]  64 49 45 71 6B B2 6E 09
  vcanS101xxEXT-1  146   [7]  2E A6 CF 44 1A E9 2A
  vcanS101xxEXT-1  508   [0]
  vcanS101xxEXT-1  726   [8]  B0 B5 2E 62 70 89 78 4F
  vcanS101xxEXT-1  454   [2]  15 01