11-19-2021 10:42 PM
Greetings,
In order to write a digital output point in DAQmx, I use DAQmxCreateTask to first create a task, then DAQmxCreateDOChan to create the channel.
I'm working in exception handling as much as possible, and have a need to test a Task for whether it contains any Channels or not.
I have the DAQmxCreateTask and DAQmxCreateDOChan in a block that break statements will terminate. If the create task isn't successful, I log an error and break out of the block. If it is successful, I proceed to creating a task. If this is not successful, I again break out of the block and proceed to shutting down the program.
In the code that shuts down the program, I have a line that writes to a digital point in this Task and channel. But I need to be able to NOT write the point if the creation of the channel was not successful.
I can test my TaskHandle to see if the task was created, but if it was, how do I test the TaskHandle to see if a channel was created or not?
(It throws another error in the shutdown when writing the digital point if the channel failed to create, so I need to not write the point if the channel was not created. How can I tell?)
Thanks!
Solved! Go to Solution.
11-19-2021 11:24 PM
LabVIEW has a property node for DAQmx Task that can query for the channels contained in the task and the number of channels. There should be something similar in CVI too.
11-21-2021 05:26 PM
Indeed there is!
This instruction will return the number of channels in the task, which in your case can be enough:
DAQmxGetTaskAttribute (..., DAQmx_Task_NumChans, &nchan, ...);
You can additionally call the same function with DAQmx_Task_Channels attribute to retrieve the name of the channels in the task.
11-27-2021 07:50 PM
Thanks! I blindly looked and didn't find anything. My solution was to put a wrapper around the handle that included a Boolean flag I would set when the Channel was created. Works, but I like this approach much better!