Fixed /dev identifier to physical USB port

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
aml5600
Posts: 5
Joined: Mon 29. Feb 2016, 19:13

Fixed /dev identifier to physical USB port

Post by aml5600 » Tue 17. May 2016, 15:17

Hi all,

At the moment I have an application utilizing two PCAN-USB adapters. Is it possible to create an environment where rather than the the first device to be plugged in is identified by channel 0x51, the second by 0x52, etc., the channels are linked to the physical ports?

So if the device is plugged in to the front right USB port it will operate on channel 0x51, back right 0x52, front left 0x53, and so on?

Thank you for any help!

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Fixed /dev identifier to physical USB port

Post by PEAK-Support » Wed 18. May 2016, 09:17

Please see here
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

aml5600
Posts: 5
Joined: Mon 29. Feb 2016, 19:13

Re: Fixed /dev identifier to physical USB port

Post by aml5600 » Wed 18. May 2016, 09:43

Hi,

I had found that guide but it is for Windows. I am working in a Linux environment.

M.Maidhof
Support
Support
Posts: 1753
Joined: Wed 22. Sep 2010, 14:00

Re: Fixed /dev identifier to physical USB port

Post by M.Maidhof » Wed 18. May 2016, 17:23

Hi,

you have to set an unique device number to each PCAN-USB, and use the udev rules to create the needed devices. Please use driver version 8.x and have a look in the manual on page 12-16 for more details.

regards

Michael

aml5600
Posts: 5
Joined: Mon 29. Feb 2016, 19:13

Re: Fixed /dev identifier to physical USB port

Post by aml5600 » Wed 18. May 2016, 23:36

Hi,

Using a Windows machine I gave my two devices unique device IDs.

As far as the devices go, I was working on a workaround before your response. To check which physical adapter is at each channel I:
- Loop through each channel and check its channel status.
- If it is available I initialize it.
- Then I use GetValue to query the device ID (which required modifying libpcanbasic.cpp, see here)
- Save the channel/device id pair and uninitialize the channel.

This works well the first time after the USB devices are plugged in. Any time after that errno = 2 is set after the ioctl() call in CAN_GetValue(). The strerror result is "No such file or directory". Once the devices are unplugged/plugged in again it works once.

Am I missing something? Any thoughts?

Thanks.

aml5600
Posts: 5
Joined: Mon 29. Feb 2016, 19:13

Re: Fixed /dev identifier to physical USB port

Post by aml5600 » Thu 19. May 2016, 12:26

I went at the problem from another direction and it is working well now...

Rather than query each device for its number, I make a system call to read the /proc/pcan file and parse it from there. Specifically, 'cat /proc/pcan | grep 0x001c' since it is the same for all USB devices.

From here I can get the channel from *n and the device ID from irq, no need for CAN_GetValue calls.

Post Reply