Tuesday, June 23, 2009

Playing a bit with SocketCan and its utilities

This time I had a better look at the SocketCan utilities that I mentioned in a previous post. As I have already told, you can get and install them with these commands:
svn checkout http://svn.berlios.de/svnroot/repos/socketcan/trunk canbus
cd canbus/can-utils/
make install

And you will end up with lots of new programs under /usr/local/bin:
asc2log canbusload candump cangen
canlogserver canplayer cansend cansniffer
isotpdump isotprecv isotpsend isotpsniffer
isotptun log2long slcand slcanpty vcan

To see how canbus works, I tried to setup a virtual can bus with these commands:

modprobe vcan can-raw
ip link add dev vcan-test type vcan
ifconfig vcan-test up

These basically creates a canbus named vcan-test and set the interface up.
Then I opened two terminals and ran the command candump on one terminal and the command cansend on the other terminal. These are the outputs:
# cansend vcan-test 5A1#11.2233.44556677.88
# cansend vcan-test 5A1#11.2233.44556677
# cansend vcan-test 1F334455#1122334455667788

# candump vcan-test
vcan-test 5A1 [8] 11 22 33 44 55 66 77 88
vcan-test 5A1 [7] 11 22 33 44 55 66 77
vcan-test 1F334455 [8] 11 22 33 44 55 66 77 88

That are the message id and the data. The number between the brackets is the data length and the last case is with an extended id.

This could also be the text format used by the slcan driver to communicate via serial port.
I have tried to use slcanpty to attach the vcan-test interface to a pseudo terminal but without success so far. I will have to try again soon as it could be the way to gather the data on the Linux machine without writing an additional custom layer.

No comments:

Post a Comment