On 02.08.2011 17:58, Max S. wrote: > Hello, Hi Max,
> I would like to know if and how socketcan supports hotpluging. > > I'm using a usb device (PCANUsb). in general the PCAN driver comes with some udev rules that set up the chardev CAN devices (like /dev/pcan32, etc). These udev rules are not very relevant to the netdevices called can0, can1, ... that are created additionally when the PEAK driver detects it's USB hardware. > What are the basics of making a socket device hotplugable, and what does > that look like in C? > > If a socket file descriptor disappears, you will get a short read. How > would one know when the device reappears and recover? The problem (especially with USB devices) is that they can disappear and reappear. In the module commandline from the pcan driver you can assign netdevice names to chardevice names (see PDF doc) but there's no guarantee, that the chardev-name is chosen the same at re-plug time. The best is to create a udev rule, that checks the 'irq' column in /proc/pcan which contains a device ID (usually 255) that can be modified with a PEAK tool to distinguish PCAN USB devices properly. You can use this kind of udev rule to put a defined PCAN USB device ID to a predefined CAN netdevice name (by renaming the netdev with the ip tool). In any case you would need to handle the -ENODEV in your CAN application. E.g. you can terminate the application and start it, after the udev rule recovered the correct CAN device. Or your can poll until -ENODEV does not appear when opening the socket (more precisely when using ioctl() ) :-( Regards, Oliver _______________________________________________ Socketcan-users mailing list [email protected] https://lists.berlios.de/mailman/listinfo/socketcan-users
