Scanning available CAN hardware / channels

CAN Development Packages for Windows®
Post Reply
A.Hartmann
Posts: 19
Joined: Tue 8. Oct 2013, 07:19

Scanning available CAN hardware / channels

Post by A.Hartmann » Fri 2. Oct 2015, 09:51

Hello,

PCANView has the nice function to show all available hardware interfaces in the connection window.

I'd like to have something similar for my own applications using CanApi2 (we have version 2.56.2). Is this possible and if yes, how?

Best regards,
André Hartmann
Attachments
pcanview.png
pcanview.png (48.89 KiB) Viewed 3251 times

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

Re: Scanning available CAN hardware / channels

Post by M.Maidhof » Fri 2. Oct 2015, 10:37

Hi,

you can use a for loop to scan for valid hardware handles on each driver:

Code: Select all

for(i=0;i<=MAX_HCANHW;i++)
  {
   ret=CAN_GetHwParam(i,CAN_PARAM_NAME,buff,sizeof(buff));
   if (ret==CAN_ERR_OK)
    {
    // Hardware found on hardwarehandle i
    // use handle i to get more details of the hardware by CAN_GetHwParam
    }
  }
Change the active device with SetDeviceName, to search other device drivers too (PCI, USB, ISA, DNG etc.).

Please have a look into the canapi2 help file, to get more information how to use those APIs

regards

Michael

A.Hartmann
Posts: 19
Joined: Tue 8. Oct 2013, 07:19

Re: Scanning available CAN hardware / channels

Post by A.Hartmann » Fri 2. Oct 2015, 12:34

Hi Michael,

thanks a lot for this information.

It allowed me to build a simple example, nothing fancy but working.

Only one note/question: the header file says, only Hardware 1...MAX_HCANHW permitted, so I guess the loop should run from 1?

Code: Select all

for (int i = 1; i <= MAX_HCANHW; i++) {
  // ...
}
Anyway, thanks for your fast help.

Best regards,
André
Attachments
own_scan.png
own_scan.png (28.41 KiB) Viewed 3243 times

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

Re: Scanning available CAN hardware / channels

Post by M.Maidhof » Fri 2. Oct 2015, 12:55

Hi,

"0" is equal to an internal hardware, when the pcan-network is not linked to a real PCAN hardware. That is why a hardware handle of 0 is still possible in the canapi2. But you are right, in that context you can start with 1, because 0 will always return ILLHW.

regards

Michael

Post Reply