2

我有一个与 NI DAQ 卡接口的 C++ 应用程序,但是设备的名称是硬编码的,如果在 NI Max 应用程序中更改它将停止工作,所以有没有办法枚举连接的设备以​​了解卡的名称那是连接的?

4

1 回答 1

1

可以使用 检索所有设备的列表DAQmxGetSysDevNames()。名称以逗号分隔。

获得所有名称的列表后,您可以使用产品类型来查找正确的设备。

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
            }               
        }
    }
}
于 2022-02-09T11:35:52.263 回答