Skip to contentSkip to conversation

Trying to use ESD CAN-USB with SocketCAN

DISCUSSION GeoffO 3 participants 5 messages Feb 28, 2013 CAN network drivers

lore
Share & tools
lore

GeoffO

author
#0 lore raw

I wanted to setup SocketCAN on my PC to prepare for an embedded Linux project, so I purchased a USB device from ESD who claimed it supports SocketCAN. I could not get it to work after the following these steps:
Downloaded and installed can-utils
Loaded modules to the kernal
sudo modprobe can
sudo modprobe can_raw
sudo modprobe can_bcm
sudo modprobe vcan

Checked that modules are loaded
lsmod | grep can
vcan 1314 0
can_bcm 11942 0
can_raw 5381 0
can 21728 2 can_bcm,can_raw

Plugged-in ESD CAN-USB/Micro and got this new device
/dev/ttyACM0

Tried to attach the USB device to SocketCAN
sudo slcan_attach /dev/ttyACM0
ioctl TIOCSETD: Invalid argument

I got this error, so I checked the code of slcan_attach to find the problem, and wrote this small program to isolate the problem:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#define LDISC_N_SLCAN 17 // default slcan line discipline since Kernel 2.6.25 int main(int argc, char **argv)

{
	int fd;
	int ldisc = LDISC_N_SLCAN;
	char *tty = "/dev/ttyACM0";//device for ESD CAN/USB Micro
	if ((fd = open (tty, O_WRONLY | O_NOCTTY)) < 0) {
		perror(tty);
		exit(1);
	}
	// set slcan line discipline on given tty
	if (ioctl (fd, TIOCSETD, &ldisc) < 0) {
		perror("ioctl TIOCSETD");
		exit(1);
	}
	return 0;
}

This program writes "ioctl TIOCSETD: Invalid argument" to the consul. The problem is apparently caused when ioctl() tries to set the LDISC_N_SLCAN line discipline for /dev/ttyACM0 and detects an invalid argument. I tried setting the line discipline to N_TTY and it did not complain. I am running Ubuntu 10.04 with kernal version 2.6.32. Any Idea what might be the problem? Is this device supported by by SocketCAN? ESD claims it is.

#1 lore raw

Am 28.02.2013 18:57, schrieb GeoffO:

Quoted 4 lines

Tried to attach the USB device to SocketCAN
sudo slcan_attach /dev/ttyACM0
ioctl TIOCSETD: Invalid argument

Did you test the communication with the device with raw slcan commands? Like cat /dev/ttyACM0 and echo -ne "O" > /dev/ttyACM0 ?

#4 lore raw
In reply to GeoffO
Quoted 7 lines · GeoffO

I wanted to setup SocketCAN on my PC to prepare for an embedded Linux project, so I purchased a USB device from ESD who claimed it supports SocketCAN.

Plugged-in ESD CAN-USB/Micro and got this new device
/dev/ttyACM0

Ugh?!

The ESD USB/Micro is a separate USB CAN driver, see:

http://lxr.linux.no/#linux+v3.8.1/drivers/net/can/usb/Kconfig#L9

and

http://lxr.linux.no/#linux+v3.8.1/drivers/net/can/usb/esd_usb2.c

Therefore i wonder why a /dev/ttyACM is created and not just a 'can0'.

Can you send the dmesg output when plugging the interface? What kernel version do you use?
What does 'lsusb -v -v' tell about the ESD adapter?

Regards,
Oliver

#2 lore raw
In reply to uescher

Thanks for the quick reply. Good suggestion. I will try to get it wired
up to something today I can communicate to.

Am 28.02.2013 18:57, schrieb GeoffO:

Quoted 4 lines

Tried to attach the USB device to SocketCAN
sudo slcan_attach /dev/ttyACM0
ioctl TIOCSETD: Invalid argument

Did you test the communication with the device with raw slcan commands? Like cat /dev/ttyACM0 and echo -ne "O" > /dev/ttyACM0 ?

#3 lore raw

Am 28.02.2013 22:27, schrieb Geoff Olson:

Quoted 2 lines

Thanks for the quick reply. Good suggestion. I will try to get it wired
up to something today I can communicate to.

It should work without an real CAN-Bus.
You can ask the CAN-USB about his Version and so things. If the communication with slcan work, the you will get an answer.