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
Scanning available CAN hardware / channels
-
- Posts: 19
- Joined: Tue 8. Oct 2013, 07:19
Scanning available CAN hardware / channels
- Attachments
-
- pcanview.png (48.89 KiB) Viewed 6552 times
Re: Scanning available CAN hardware / channels
Hi,
you can use a for loop to scan for valid hardware handles on each driver:
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
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
}
}
Please have a look into the canapi2 help file, to get more information how to use those APIs
regards
Michael
-
- Posts: 19
- Joined: Tue 8. Oct 2013, 07:19
Re: Scanning available CAN hardware / channels
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?
Anyway, thanks for your fast help.
Best regards,
André
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++) {
// ...
}
Best regards,
André
- Attachments
-
- own_scan.png (28.41 KiB) Viewed 6544 times
Re: Scanning available CAN hardware / channels
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
"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