Linux Users

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxBaseGetSystemInfoAttribute missing on linux

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++?

0 Kudos
Message 1 of 6
(4,839 Views)

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:

  1. Use VISA Find Resource (viFindRsrc) to search for:
    • PXI?*INSTR, which is an expression that will restrict results to PCI devices,
    • USB?*::0x3923::?*::RAW, for USB devices.
  2. Use VISA Open (viOpen) to query the model codes (viGetAttribute with VI_ATTR_MODEL_CODE) for each device, and VISA Close (viClose) to release the device.
  3. Match the Vendor and Product IDs to the devices you want to be able to discover.
    • NI's PCI VID is 0x1093
    • NI's USB VID is 0x3923
  4. The order in which DAQmx Base assigns names, like Dev1, is the order in which VISA returns devices, and PCI devices precede USB devices.

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)
Message 2 of 6
(3,890 Views)

Hi,

the second way is to parse command lsdaq

0 Kudos
Message 3 of 6
(3,890 Views)

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

        }

      }

0 Kudos
Message 4 of 6
(3,890 Views)

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)

0 Kudos
Message 5 of 6
(3,890 Views)

@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.

0 Kudos
Message 6 of 6
(3,890 Views)