8 can bus examples, Ktam3874/pitx software guide, 1 can loopback test utility – Kontron KTAM3874-pITX User Manual

Page 75

Advertising
background image

KTD-S0057-I

Page 71 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide

10.8 CAN Bus Examples

10.8.1 CAN Loopback Test Utility

The following picture shows a simple wiring plan for the loopback test. With very short cables you need no
termination resistors.


It is possible that the program does not work correctly after start-up. In this case you should execute the
commands below (naturally you can use another baudrate than 125 kBaud):

sudo ifconfig can0 down
sudo ifconfig can1 down
sudo ip link set can0 up type can bitrate 125000
sudo ip link set can1 up type can bitrate 125000

Further details about CAN bus and socket programming is available on

https://www.kernel.org/doc/Docu-

mentation/networking/can.txt

and also on

http://www.can-cia.org/fileadmin/cia/files/icc/13/hartkopp.pdf

.

As an exception this program can run with user and root rights (compiled on Ubuntu

TM

distribution).

/* CAN bus test program

* Copyright (c) 2013 Kontron Technology A/S

* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*/

#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>

Advertising
This manual is related to the following products: