Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I remove a Task Channel and then recreate it?

I'm writing an application in C# on a Windows XP platform using version NI-DAQmx version 7.4. I need to be able to create a task, add channels to it, then delete those channels and add new channels.
 
For example, I create a channel using the CreateVoltageChannel function, then I call the Dispose function which I thought would remove it.  But if I make a subsequent call to the CreateVoltageChannel function, I get an error stating that I'm trying to read or write protected memory.  I've been trying to find a way to explicitly remove channels from a Task, but the documentation suggests that the Dispose function does this.  If so, why can't I create a new channel?
 
Thanks,
Joy
 
 
 
0 Kudos
Message 1 of 4
(4,143 Views)
Hi Joy,

Unfortunately there is not way to remove channels from a task currently.  When you get a reference to a channel it actually returns a copy of the channel rather than a reference to the channel inside the task.  This means the dispose function does not remove the channel from the task.

If you need to have different channels in a task, it is recommended to clear the current task to free up the reserved resources and then create a new task with the new channels.

Regards,
Andrew W
National Instruments
0 Kudos
Message 2 of 4
(4,130 Views)


TheWoost wrote:

If you need to have different channels in a task, it is recommended to clear the current task to free up the reserved resources and then create a new task with the new channels.



Does this hold true for triggers on a channel? I have one task, with a finite set of channels, but I want to dynamically change how data is collected of them. Sometimes I want to get one point from each channel (single read, no trigger) other times I want to use a reference tirgger to read N samples from all the channel asyncronously.
0 Kudos
Message 3 of 4
(3,876 Views)
Tyzack,

After stopping a task you are able to make modifications to the task. This means you should be able to modify the trigger options. Please continue this discussion at your other thread here.
Regards,

Chris Delvizis
National Instruments
0 Kudos
Message 4 of 4
(3,861 Views)