Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Persistence of CreateChannel() Method

I'm new to using DAQmx / C# for writing a DAQ application. I have a USB-6001 connected to my computer. Some of the digital ports are used as outputs while others are inputs. I can read the state of my digital input lines successfully.

 

What I'm not clear about is how persistent is an operation to set a line to a digital output? For instance, here is my code to set the state of a single digital output line (pardon the messed up formatting):

 

try
{
    using (NationalInstruments.DAQmx.Task digitalWriteTask = new NationalInstruments.DAQmx.Task())
    {
        digitalWriteTask.DOChannels.CreateChannel(sPortText, sChannelName, ChannelLineGrouping.OneChannelForAllLines);

        DigitalSingleChannelWriter writer = new DigitalSingleChannelWriter(digitalWriteTask.Stream);

        writer.WriteSingleSampleSingleLine(true, bIsOn);

        bWroteOK = true;
    }
}
catch (DaqException ex)
{
     bWroteOK = false;
}

 

How long will the channel specified in sPortText remain as an output in the desired state?

  • Until digitalWriteTask goes out of scope?
  • Until another task is created that might try to use that channel as an input?
  • Until a later call to Device method Reset() is made?
  • Until the application shuts down?

Thanks in advance,

Ken

0 Kudos
Message 1 of 3
(2,876 Views)

Hi Ken, 

 

I think I understand your question, but please clarify if I am mislead. 

 

When you create a virtual channel (what you are doing with sPort) those lines (and more importantly the resources associated with the task) will remain reserved until you clear the task. So, if you try to configure another task with anything reserved by the previous one, you would get a resource reserved error. 

 

Let me know if this helps or if you have follow ups! 

 

Best, 

Clint T.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 3
(2,829 Views)

Hi Clint,

 

Thanks for taking the time to reply and the information.

 

What I was actually trying to figure out was if I were to set a digital output to a particular state, would it remain in that state even after the task went out of scope in my example code. I found that was the case be writing some test code and doing some experimenting with my hardware.

 

Thanks again for taking the time to reply.

Ken

0 Kudos
Message 3 of 3
(2,823 Views)