Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx: How to query the list of devices in ANSI C?

Solved!
Go to solution

Hello,

 

LabVIEW has a DAQmx System property node, which has a Device Names item. This returns a list of DAQmx devices on my system.

 

I was looking for an equivalent function in the ANSI C library (http://zone.ni.com/reference/en-XX/help/370471AF-01/TOC3.htm ), but couldn't find anything. Does this function exist?

 

Thanks!

Certified LabVIEW Developer
0 Kudos
Message 1 of 4
(4,772 Views)
Solution
Accepted by topic author JKSH

You'll want to look in the "NI-DAQmx C Properties" section. The C equivalent to LabVIEW's DAQmx System→Device Names property is DAQmxGetSysDevNames.

——
Brandon Streiff
ni.com/compactdaq · ni.com/daq
Message 2 of 4
(4,743 Views)

Hello,

 

the DAQmxGetSysDevNames function uses a character pointer (char *data) as an argument. What should I use for this? Should I just define an empty character array and then use its pointer in the DAQmxGetSysDevNames function? I haven't been able to find an example ANSI C code for this function. As you can probably tell I am very new to programming. 

 

Regards, 

0 Kudos
Message 3 of 4
(4,212 Views)

The documentation for that function, unfortunately, is quite lacking.

 

The operative documentation is How Do I Dynamically Choose the Size of an Array to be Passed to a NI-DAQmx C Function?, and my answer on Why does DAQmxGetDevAOVoltageRngs return 4 values? demonstrates the approach. That example was for a function returning an array of floating point values, but the same general principle applies with a string (in C, an array of characters)-- calling with a NULL pointer and a length of 0 will return the required buffer size, when you then have to allocate.

 

/* NOTE: for sake of brevity, error handling has been elided in this example */
int32 status; int32 stringLength; /* get number of characters */ stringLength = DAQmxGetSysDevNames(NULL, 0); if (stringLength < 0) { /* handle error */ } else { char *deviceNames = (char *)calloc(stringLength, sizeof(char)); if (!deviceNames) { /* handle allocation failure */ } status = DAQmxGetSysDevNames(deviceNames, stringLength); if (status < 0) { /* handle failure */ } printf("Devices: %s\n", deviceNames);
free(deviceNames); }

For properties that return a list of devices or channels, as DAQmxGetSysDevNames does, the format is (loosely) documented in Physical Channel Syntax; it is a comma-and-space separated list. For example:

cDAQ3, cDAQ3Mod1, cDAQ3Mod4, cDAQ3Mod6

 

——
Brandon Streiff
ni.com/compactdaq · ni.com/daq
0 Kudos
Message 4 of 4
(4,203 Views)