Loop through the possible devices to detect the available ones

The free CAN Software API (Application Programming Interface) for Windows®
Locked
tuttoaldoc
Posts: 24
Joined: Fri 15. Mar 2019, 14:44

Loop through the possible devices to detect the available ones

Post by tuttoaldoc » Thu 23. May 2024, 14:54

Hello,
I'm developing a small C application based on PCANBasic dll. At the init I loop through the possible devices (from PCAN_USBBUS1 to PCAN_USBBUS16 and from PCAN_LANBUS1 to PCAN_LANBUS16) trying to see if they are present or not to create a list of the available ones. To do that, based on the examples provided I do an un-initialize calling PCAN_Uninitialize (just to be sure there is no pending init) and then an initialize calling PCAN_Initialize: if the return is ok I read some params like HW Name, .. and I deinit the channel calling back PCAN_Uninitialize.
Everything seems to work but sometimes my application hungs at PCAN_Uninitialize or PCAN_Initialize call. I tried to add a delay but I still have the problem. I checked in the forum but I was not able to find a topic open on this type of issue.
Do you have any suggestion?
thanks
Michele

K.Wagner
Software Development
Software Development
Posts: 1080
Joined: Wed 22. Sep 2010, 13:36

Re: Loop through the possible devices to detect the available ones

Post by K.Wagner » Thu 23. May 2024, 15:50

Hello,

you do not need to iterate anymore on all possible channels. Rather you can just use the parameter PCAN_ATTACHED_CHANNELS, which gives you already a list with all available channels. For more information check this parameter within the API documentation, or check the sample function "GetPCAN_ATTACHED_CHANNELS" within the native C++ project sample "02_getSetParameter" (Samples\Samples.zip\Console\NativeC++\02_GetSetParameter), which is delivered together with the PCAN-Basic package.
Best regards,
Keneth

tuttoaldoc
Posts: 24
Joined: Fri 15. Mar 2019, 14:44

Re: Loop through the possible devices to detect the available ones

Post by tuttoaldoc » Fri 24. May 2024, 08:51

Hi,
thank you very much it works fine. The only issue I have is that we use PCAN usb devices but also PCAN-Ethernet Gateways and in order to distinguish them I was planning to use the device-id for the usb ones and the ip-address for the network ones because it seems to me the device id is not managed in the network ones .. or at least I cannot find in the gateway webpage a point where I can set it.
thanks for your support
michele

K.Wagner
Software Development
Software Development
Posts: 1080
Joined: Wed 22. Sep 2010, 13:36

Re: Loop through the possible devices to detect the available ones

Post by K.Wagner » Fri 24. May 2024, 09:29

Hello,

the ID is also handled by the PCAN-Gateways devices. This was included within the PCAN-gateway Software version 2.9.0 (August 2020)
DeviceID-Gateway.png
DeviceID-Gateway.png (41.09 KiB) Viewed 4453 times
If you have a software version equal or grater to 2.9.0, then you should be able to set the Device ID using
PCAN-View,
DeviceID-PCAN-View.png
DeviceID-PCAN-View.png (67.17 KiB) Viewed 4453 times
PEAK-Settings,
DeviceID-PEAK-Settings.png
DeviceID-PEAK-Settings.png (103.75 KiB) Viewed 4453 times
and PCAN-Basic
DeviceID-PCANBasic.png
DeviceID-PCANBasic.png (40.41 KiB) Viewed 4453 times
Note that the Device-ID cannot be set directly in the PCAN-Gateway device.
Best regards,
Keneth

tuttoaldoc
Posts: 24
Joined: Fri 15. Mar 2019, 14:44

Re: Loop through the possible devices to detect the available ones

Post by tuttoaldoc » Fri 24. May 2024, 12:37

Thank you very much, I was looking in the web interface. It works perfectly.
Thank you so much for the support
regards
Michele

K.Wagner
Software Development
Software Development
Posts: 1080
Joined: Wed 22. Sep 2010, 13:36

Re: Loop through the possible devices to detect the available ones

Post by K.Wagner » Fri 24. May 2024, 12:43

You are welcome. Closed.
Best regards,
Keneth

Locked