c++nidaqmxdaq-mx

Is there a way to enumerate interfaces using NI Daqmx


I have a C++ application interfacing with a NI DAQ card, however the name of the device is hard coded and if changed in the NI Max app it would stop working, so is there a way to enumerate connected devices to know the name of the cards that are connected ?


Solution

  • List of all devices can be retrieved with DAQmxGetSysDevNames(). The names are separated by commas.

    Once you have the list of all names, you can use the product type to find the correct device.

    const std::string expectedProductType = "1234";
    constexpr size_t bufferSize = 1000;
    char buffer[bufferSize] = {};
    if (!DAQmxFailed(DAQmxGetSysDevNames(buffer, bufferSize))) {
        std::string allNames(buffer);
        std::vector<std::string> names;
        boost::split(names, allNames, boost::is_any_of(","));
        for (auto name : names) {
            char buffer2[bufferSize] = {};
            if (!DAQmxFailed(DAQmxGetDevProductType(name.c_str(), buffer2, bufferSize))) {
                if (expectedProductType == std::string(buffer2)) {
                    // match found
                }               
            }
        }
    }