MIO04 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 MIO04 CAN interface via the Io4Edge API.
- A target machine running Linux that is in the same network as your MIO04
A development PC (Windows or Linux), connected via Network to the target machine
- CANbus with at least one CAN device
- Cable to connect the CAN device with the MIO04
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
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 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
On your target machine, 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
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.
The demo must be compiled for the architecture of your target machine. Typical targets are:
- modern x86 PCs: Architecture =
- RaspberryPi (32 Bit):
In the following examples, we use
Run this in a powershell console
cd examples\canL2\streamDump $Env:GOOS = "linux" $Env:GOARCH = "arm" go build
cd examples/canL2/streamDump GOOS=linux GOARCH=arm go build
This produces the binary file
streamDump in the current folder.
Copy Demo to target machine
Transfer the compiled binary. Replace
<target-ip> with the IP address of your target machine.
scp streamDump <target-ip>:/~
Running the Demo
Login into your target machine over SSH:
Once logged in into the target machine’s Shell, run the demo.
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 ...