Fixing hardware handles on a PCAN-USB Pro

High-speed USB 2.0 to CAN/LIN Interface
Post Reply
K.Wagner
Software Development
Software Development
Posts: 732
Joined: Wed 22. Sep 2010, 13:36

Fixing hardware handles on a PCAN-USB Pro

Post by K.Wagner » Thu 10. May 2012, 12:58

USB devices from Peak (PCAN-USB, PCAN-USB Pro, etc.) are "logged-in" on a system with a handle that identifies each hardware connected to the computer in a given time. The same handle is not always used for the same device since it depends on the sequence as the devices were plugged into the USB ports.

But sometimes, specially if your are programming an application (using PCAN-Basic, PLIN-API, etc.) to work with several devices on the same computer, you may need to unequivocally differentiate the available devices, that is, you need to know the handle of a device in every moment, not worrying about when it was plugged in or if the computer was restarted, etc.

If you need to use fixed hardware handles within the CAN part of an USB Pro, please see this topic. Otherwise, if you need fixed hardware handles using the LIN Part of an USB Pro, keep reading.

The best way to explain this is with a practical example. Imaginate that you have an application which has to communicate with the first LIN channel of a specific PCAN-USB Pro device. You could do the following:

First of all, each LIN Channel has a Hardware-ID that can be configured. This ID has a size of 4 bytes and can be changed using the current version of the PEAK Control Panel Applet.

Lets say you have a PCAN-USB pro Device with it first LIN Channel configured with the ID 10:
PEAK Control Panel Applet
PEAK Control Panel Applet
FixingHardwareHandle2.jpg (162.72 KiB) Viewed 10894 times
After you have set the ID, a few values must be added in the Registry in order to create and fix a desired hardware handle. By the way, the LIN hardware handles are assigned beginning with 1. Since such a handle has a size of two bytes, you can use a handle value of up to 65535.

The registry entry for our example looks like:
Registry
Registry
FixingHardwareHandle.jpg (191.28 KiB) Viewed 10894 times
Value Name:
The name of the created registry value tells the LIN driver which handle will be fixed. In our example we are fixing the handle 1:
Hardware1 --> LIN-Hardware Handle 1
...

Value Data:
The data of a created registry value tells the LIN driver which physical hardware (LIN channel on a PCAN-USB Pro device) must be associated to the handle specified within the value name. In our example, the hardware handle 1 will exists only when the LIN Hardware with ID 10 is available/plugged-in.


...And... that is it. After restarting the computer (or disconnecting and reconnecting again your hardware) your application will always communicate with the same LIN channel when connecting to the Hardware handle 1, indifferently of how many PCAN-USB Pro are connected to the computer or their plugging order. :D
:!: Ensure that the IDs that you use for each hardware (each LIN channel of each PCAN-USB Pro device used) are unique when connected in the same machine. Having duplicated IDs cause undesired behaviors :!:

If you see the pictures again you will see that there is a second hardware fixed (Hardware handle 2 / Hardware ID 0). This is intended to show that it is not needed to use consecutive hardware handles in order to fix them, and that the channels can be physically found even in different devices.
Best regards,
Keneth

ctag_dmv
Posts: 2
Joined: Mon 20. Oct 2014, 10:03

Re: Fixing hardware handles on a PCAN-USB Pro

Post by ctag_dmv » Mon 20. Oct 2014, 10:17

Hi,

We are using this method to indentify can interfaces in Linux. Following the indications we found that when we set "device id"=20h (decimal 32) it only changes the first can device id in Linux (column irq). The second remains 0 always:

Code: Select all

cat /proc/pcan 

*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20140723_n (7.12.0) Oct  7 2014 16:31:37 --------------
*------------- [mod] [isa] [pci] [dng] [par] [usb] [pcc] [net] --------------
*--------------------- 2 interfaces @ major 252 found -----------------------
*n -type- ndev --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32 usbpro can1 ffffffff 032 0x001c 00000000 00000000 00000000 00000000 0x0000
33 usbpro can2 ffffffff 000 0x001c 00000000 00000000 00000000 00000000 0x0000
Is there a way to assing a different interface id to each channel? If this is not the case, how can we know which usbpro device a second channel with device id = 0 belongs to? We are configuring a system with 2 usb pro to get 4 channels.

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

Re: Fixing hardware handles on a PCAN-USB Pro

Post by M.Maidhof » Mon 20. Oct 2014, 17:46

Hi,

which tool did you use to set the device number (Windows: PCAN-View, or Linux: pcan_settings)?

regards

Michael

ctag_dmv
Posts: 2
Joined: Mon 20. Oct 2014, 10:03

Re: Fixing hardware handles on a PCAN-USB Pro

Post by ctag_dmv » Tue 21. Oct 2014, 09:31

We were using PCAN-View, but as you commented it we tested pcan-settings and we were able to set device id per channel. Many thanks!

Post Reply