Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Detect DNET card

Hi,
 
What is the best way to detect all the NI DNET cards installed in your computer? Currently, I try to open each interface (
to see if it is available (I use ncOpenDnetIntf() and iterate through "DNET0"...."DNET63" and see if that call is successful).
There must be a better way? Iterating through all the IDs are very time consuming..
 
Thanks,
0 Kudos
Message 1 of 8
(4,738 Views)
Hi Haugan,

NI-DNET does not give you the tools but you can use the ncGetHardwareInfo() from NI-CAN for a more elegant way to solve this. In pseudo code:

ncGetHardwareInfo(1, 1, NC_ATTR_NUM_CARDS, 4, &number_of_cards)
FOR card=0 TO number_of_cards {
    // make sure, it’s a Series 1 CAN card,
    // as NI-DNET does not work with Series 2 NI CAN hardware

    ncGetHardwareInfo(card, 1, NC_ATTR_HW_SERIES, 4, &series)
    IF (series == NC_HW_SERIES_1) {
        // make sure, it’s a high-speed CAN card,
        // as NI-DNET does not work with low-speed CAN hardware

        ncGetHardwareInfo(card, 1, NC_ATTR_TRANSCEIVER_TYPE, &type)
        IF (type == 0) {
            ncGetHardwareInfo(card, 1, NC_ATTR_INTERFACE_NUM, &interface)
            PRINT ("DNET%d, ", interface)
        }
    }
}

If you only have 'real' NI-DNET hardware (1-port, series 1, high-speed NI CAN cards), you don't need the blue portion of the code.

-B2k
0 Kudos
Message 2 of 8
(4,724 Views)
Hi,

You mean "FOR card=1 TO number_of_cards {"?

I tried iterating from 0 but that gave me a status error saying that one of the arguments to the ncGetHardwareInfo()function call was wrong.

Also, I get an unknown (0xFF) tranceiver type when I query for NC_ATTR_TRANSCEIVER_TYPE.
0 Kudos
Message 3 of 8
(4,709 Views)
What driver versions are you working with?  NI-CAN?  NI-DNET?  Have you tried upgrading to a newer revision?  Does the function mentioned above always return FF, or is just with Series 1 cards?
 
Logan S.
0 Kudos
Message 4 of 8
(4,687 Views)
Hi,
 
I haven't tried it with other cards than the one I have. However, the card says that it supports both high-speed and low-speed CAN.
I am using the latest NI-DNET drivers (1.4.2).
 
Thanks,
0 Kudos
Message 5 of 8
(4,690 Views)
Hi Haugan,

From your description (the card says that it supports both high-speed and low-speed CAN), I assume that you have a PCMCIA card. ncGetHardwareInfo(NC_ATTR_TRANSCEIVER_TYPE) is not supported on the PCMCIA form factor, which explains your return value of 0xFF.
Further more, all NI-CAN/NI-DNET function calls return a status, so all calls should be execute like this:

status = ncGetHardwareInfo(card, 1, NC_ATTR_TRANSCEIVER_TYPE, &type)
IF (status <> 0)
  PRINT ("ncGetHardwareInfo returned error code %d", status)

That way, you know if the function even executed successfully. Here's the modified code (however, it doesn't check the status to make it more readable).

status = ncGetHardwareInfo(1, 1, NC_ATTR_NUM_CARDS, 4, &number_of_cards)
FOR card=1 TO number_of_cards {
    // make sure, it’s a Series 1 CAN card,
    // as NI-DNET does not work with Series 2 NI CAN hardware
    status = ncGetHardwareInfo(card, 1, NC_ATTR_HW_SERIES, 4, &series)
    IF (series == NC_HW_SERIES_1) {
        // check, if it's a PCMCIA card, as we can't
        // query the transceiver type for this form factor
        status = ncGetHardwareInfo(card, 1, NC_ATTR_HW_FORMFACTOR, 4, &formfactor)
        IF (formfactor <> NC_HW_FORMFACTOR_PCMCIA) {
           // make sure, it’s a high-speed CAN card,
           // as NI-DNET does not work with low-speed CAN hardware
           status = ncGetHardwareInfo(card, 1, NC_ATTR_TRANSCEIVER_TYPE, &type)
           IF (type == 0) {
               status = ncGetHardwareInfo(card, 1, NC_ATTR_INTERFACE_NUM, &interface)
               PRINT ("DNET%d, ", interface)
           }
        }
    }
}


Again, if you only have 'real' NI-DNET hardware (1-port, series 1, high-speed NI CAN cards), you don't need the blue portion of the code.

-B2k
0 Kudos
Message 6 of 8
(4,669 Views)
Attached is a VB example that I wrote that might help.  It's not perfect, but give it a shot, if you are in VB.
 
Logan S.
0 Kudos
Message 7 of 8
(4,665 Views)
Thanks!

Your example was very helpful.
0 Kudos
Message 8 of 8
(4,597 Views)