04-23-2015 05:17 AM
I am trying to find out in Linux what NI devices are installed using NI DAQmxBase 3.7.0 on Linux. Under windows I can do the following:
DAQmxGetSystemInfoAttribute(DAQmx_Sys_DevNames,devicenames);
but the equivalent is missing under linux and commented out in the header file. I tried copying the definition, but it has been removed from the library too.
I need to programmtically find the installed devices and channels. Anyone know how this can be done in Linux in C++?
04-23-2015 08:53 AM
SimonSparkes wrote:
I need to programmtically find the installed devices and channels. Anyone know how this can be done in Linux in C++?
DAQmx Base doesn't offer dynamic device detection and listing as part of its API, but you can use VISA [1] to accomplish your task. The basic approach is:
For a starting place, I would recommend the VISA FindRsrc example in \usr\local\vxipnp\linux\NIvisa\Examples\C\General
[1] NI-VISA Programmer Reference Manual
http://digital.ni.com/manuals.nsf/websearch/87E52268CF9ACCEE86256D0F006E860D
Joe Friedchicken
NI Configuration Based Software Get with your fellow OS users
[ Linux ] [ macOS ]Principal Software Engineer :: Configuration Based Software
Senior Software Engineer :: Multifunction Instruments Applications Group (until May 2018)
Software Engineer :: Measurements RLP Group (until Mar 2014)
Applications Engineer :: High Speed Product Group (until Sep 2008)
04-23-2015 09:35 AM
Hi,
the second way is to parse command lsdaq
04-23-2015 09:41 AM
Did think of that but wanted to avoid that under windows as code must run on both platforms. So compromised with an interative loop which gave me both devices and channels. The following is the essential part of the test program written which only looks for Analog Inputs:
TaskHandle hTask;
int r;
#if defined(X_PLATFORM_WINDOWS)
r = DAQmxCreateTask("", &hTask);
#else
r = DAQmxBaseCreateTask("", &hTask);
#endif
if (r >= 0)
{
int device=0;
for (int device=1;device<16;device++)
{
XString devicename;
int channel=0;
bool seendevice=false;
bool seenchannel=false;
devicename.format("Dev%d", device);
// Analog Input channels
#if defined(X_PLATFORM_WINDOWS)
r = DAQmxCreateTask("", &hTask);
#else
r = DAQmxBaseCreateTask("", &hTask);
#endif
seenchannel = false;
for (int channel=0;channel<256;channel++)
{
XString channelname, channelpath;
channelname.format("ai%d", channel);
channelpath.format("%s/ai%d", devicename.c_str(), channel);
#if defined(X_PLATFORM_WINDOWS)
r = DAQmxCreateAIVoltageChan(hTask,
#else
r = DAQmxBaseCreateAIVoltageChan(hTask,
#endif
channelpath,
"",
DAQmx_Val_RSE,
-10.0,
10.0,
DAQmx_Val_Volts,
NULL);
// printf("create channel %s = %d\n", channelname.c_str(), r);
if (r < 0)
{
break;
}
else
{
if (!seendevice)
{
seendevice = true;
printf("Device: %s\n", devicename.c_str());
}
if (!seenchannel)
{
seenchannel = true;
printf(" Analog Inputs :");
}
printf(" %s", channelname.c_str());
}
}
if (seenchannel) printf("\n");
#if defined(X_PLATFORM_WINDOWS)
DAQmxStopTask(hTask);
DAQmxClearTask(hTask);
#else
DAQmxBaseStopTask(hTask);
DAQmxBaseClearTask(hTask);
#endif
}
}
04-23-2015 10:23 AM
Since it seems that the argument types, positions, etc. match, you can use function pointers to consolidate the platform-specific code to one location (setting the pointers)
04-23-2015 11:35 AM
@Simon
You said, that code should work on both platforms:
1. Use NI DAQmxBase on both platforms Linux and Windows.
2. Use NI DAQmx 8.0.2 for Linux and latest NI DAQmx on Windows - may be some function different in using in their parameters for example pointer of integer variable or integer variable.
3. I think, it better to divide you code on two parts in two files, for example: daqlin.h and daqwin.h and in main program
#if defined (X_PLATFORM WINDOWS)
#include "daqlin.inc"
#else
#include "daqwin.inc"
#endif
because your code is difficult to read.
I program my daq application in FreePascal and sometimes use include direcitive, but in C include is used very offen.