Using the Level II socketcan driver

Virtual interface

$ modprobe can
$ modprobe can_raw
$ modprobe can_bcm
$ modprobe vcan
$ sudo ip link add dev vcan0 type vcan
$ sudo ip link set up vcan0
$ ip link show vcan0
3: vcan0: <NOARP,UP,LOWER_UP> mtu 16 qdisc noqueue state UNKNOWN 
  link/can
  
  
"candump vcan0" tool can be used to get info.  

Tool for socketcan

Userspace Library for SocketCAN

usb2can 8Devices - Ged's adapter

Setup interface
===============
modprobe can_raw
modprobe can_dev
insmod usb_8dev.ko  (on newer kernel's (>3.2) use isnmod usb_8dev.ko )
The "8 devices" USB2CAN converter is supported by mainline linux since version 3.9. You must build
it yourself on older kernels. 
ip link set can0 up type can bitrate 125000 sample-point 0.875

The adapter must be connected of course.

Shutdown interface
==================
ip link set can0 down
rmmod usb_8dev

Use 

candump can0

to view incoming traffic 
 
If your system has a kernel < 3.9 you must download the kernel driver from here 
https://github.com/krumboeck/usb2can

Then make sure that uou have the lnux jheaders installed 

apt-get install linux-headers-$(uname -r)

And then issue 

make

which should build the driver for you.

If you want to read register 0xe0 of node 1 you can issue

./cansend  can0 00000900#01e0

this will return

can0  0C000A01   [2]  E0 77

in candump, if the 0xe0 register position contains 0x77 = “w”.

PEAK pcan adapter

Tutorial http://jansblog.org/?p=400

* Setup in german - [[http://jansblog.org/?p=400]]
* [[http://www.peak-system.com/fileadmin/media/linux/files/PCAN%20Driver%20for%20Linux_eng_7.1.pdf]]
* [[http://www.peak-system.com/fileadmin/media/linux/index.htm#download]]

On newer kernels the peak module is in the kernel. Use 'peak_usb'

Serial adapters

For Lawicel adapters etc use the slcan driver.

sudo slcand -s4 -S 57600 -t hw -o /dev/ttyUSB0
sudo ip link set up slcan0

* Comparison between serial adapters - 
    http://surfnet.dl.sourceforge.net/project/socketcan.berlios/SLCAN-API.pdf

Other links

Once the driver installed and the bitrate is set, the CAN interface has to be 
started like a standard net interface
ifconfig can0 up

and can be stopped like that:
ifconfig can0 down
Get socketcan version
cat /proc/net/can/version

The socketCAN statistics can be retrieved like that:
cat /proc/net/can/stats

candump: dump traffic on a CAN network
The following command shows the received message from the CAN bus
candump can0

cansend: simple command line tool to send CAN-frames via CAN_RAW sockets
exemple : The following command sends 3 bytes on the bus (0x1E, 0x10, 0x10) with the identifier 500.
cansend can0 500#1E.10.10

The information with the identifier 500 will be available on the bus when the 
device receive the remote     request message
cangen: CAN frames generator for testing purpose
canplayer: send CAN frames from a file to a CAN interface

These tools can be compiled and installed on the target by means of the Buildroot menuconfig:
$ make menuconfig
Package Selection for the target  --->
  Networking  --->
      [*]   Socket CAN
$ make
then, reflash your rootfs.

Carambola MCP-2551 CAN

* http://lnxpps.de/can2udpe/smallest-rocrail-server-ever/
* http://lnxpps.de/can2udpe/openwrt/

Go back

 
howto/driver_level2_sokcetcan.txt · Last modified: 2014/10/02 20:43 by svenz
[unknown button type]
 
Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki