Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NIDAQmx: return exact number of physical channels besides a char * containing their names?

Hello all,

 

from reading the NIDAQmx help files I suspect this is not possible, but nevertheless I thought I'd give it a shot: I know one can use the DAQmxGetDeviceAttribute(...DAQmx_Dev_AI_PhysicalChans...) function to get a char * containing the names of input channels on the device. Is there any way to retrieve the exact number of input channels? (besides tokenizing the char * and counting the channels?)

 

Thank you!

0 Kudos
Message 1 of 7
(3,718 Views)

See this recent post:

 

http://forums.ni.com/ni/board/message?board.id=170&thread.id=477043

 

-AK2DM

~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 2 of 7
(3,705 Views)
Thanks, I had seen that post but couldn't find the equivalent C++ NIDAQmx function! Could you perhaps give some directions regarding that?
0 Kudos
Message 3 of 7
(3,692 Views)
It's not a DAQmx function. As you said, it returns a char array. Isn't there a function in C++ to determine how many elements are in an array?
0 Kudos
Message 4 of 7
(3,685 Views)
Of course: I am tokenizing the char * and counting the individual channels encountered! I just thought perhaps NIDAQmx offered a more elegant solution that I failed to notice in the help file.
0 Kudos
Message 5 of 7
(3,680 Views)

AK2DM and Dennis, DAQmxGetDevAIPhysicalChans() in the DAQmx ANSI C API returns a single C string via an out-parameter. It uses ", " as the delimiter between channels. It doesn't return an array of pointers to C strings. If it did, then you would have to call back into DAQmx to free them, because different DLLs have different memory allocators on Windows. Also, the DAQmx ANSI C API has no flatten/unflatten channel string functions.

 

Acgrama, you're right that there is no easier or more elegant way to do this through the DAQmx ANSI C API. You'll have to tokenize the string to count the number of channels. It's easy to do this with strtok(), but this modifies the string and is not thread-safe on all platforms. It's slightly less easy to count the tokens by using strcspn() to identify the end of a token and strspn() to identify the end of a delimiter, but this approach doesn't modify the string. I would also recommend going to www.ni.com/contact and submitting product feedback about this.

 

Brad


 

 

---
Brad Keryan
NI R&D
0 Kudos
Message 6 of 7
(3,672 Views)

Sorry, thought it worked the same way as LabVIEW with the AI.PhysicalChannel property.

 

Message Edited by Dennis Knutson on 02-23-2010 01:42 PM
0 Kudos
Message 7 of 7
(3,663 Views)