Page 1 of 1

Ad-Hoc network always created in the "internal" card

Posted: Fri 8. Dec 2017, 13:43
by xelarellum
I am using the PCAN-Devloper 4 dll in an flasher application. There are no CAN networks prepared. So, my proposed workflow was:
  • connect the client
  • see if there was already a network with my settings?
  • remove this network
  • create a network with my settings to the device I want
  • connect to this network
This translates to the following code:

Code: Select all

// create client
checkResult(CAN_RegisterClient(pcan_usb, "TCanCardPeak4", 0, &clientHandle));

// check to see if we already have a network configured
res = CAN_ConnectToNet(pcan_usb, clientHandle, (LPSTR)&netName[0], &netHandle); // netName is 'TCanCardPeak4Net@256'
if (CAN_ERR_OK == res)
{
    // if yes, disconnect and remove this network
    res = CAN_DisconnectFromNet(pcan_usb, clientHandle, netHandle);
    res = CAN_RemoveNet(pcan_usb, netHandle);
}

// try to register a network for our pcan_usb hardware
HCANHW hwHandle = 1; // we want the first device
checkResult(CAN_RegisterNet(pcan_usb, 0, (LPCSTR)&netName[0], hwHandle, (can_any_bitrate_t *)&bitrate));    
All of the above succeeds without error. But first, an already existing network of this name is not removed from the driver. And second, the created network is attached to the 'intern' PCAN USB and not the real one.

Different values of hwHandle give the same results.

Any suggestions on what I am doing wrong here?

Re: Ad-Hoc network always created in the "internal" card

Posted: Fri 8. Dec 2017, 14:31
by K.Wolf
Hi,
in the standard configuration, the first PCAN-USB hardware has hardware handle 16, not 1.
In the PCAN Nets Configuration tool on the View menu you can display a 'Handle' column so you can check the actual handles of your hardware.

Re: Ad-Hoc network always created in the "internal" card

Posted: Mon 11. Dec 2017, 10:45
by xelarellum
Thanks a lot for the answer, this did the trick. Now, to get the first active hw, i loop hw and try to get the status:

Code: Select all

for (HCANHW hw = 1; hw <= MAX_HCANHW; hw++) {
        can_status_t result = CAN_GetHardwareStatus(MyDevice, hw);
        switch (result) {
        case CAN_ERR_NODRIVER:
        case CAN_ERR_ILLHW:
                // invalid hardware
                break;
        default:
                return(HCANHW)hw;
        }
}