Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem Writing to Single Digital Output Line

Good Morning,

 

I am writing a .NET application that uses the digital outputs on an NI USB-6009 to control three valves (supply, bypass, exhaust) using the following syntax:

 

private readonlyTask digitalOutputTask = newTask();

 

this.digitalOutputTask.DOChannels.CreateChannel("SupplyValve", string.Empty, ChannelLineGrouping.OneChannelForEachLine);

this.digitalOutputTask.DOChannels.CreateChannel("Bypass Valve", string.Empty, ChannelLineGrouping.OneChannelForEachLine);

this.digitalOutputTask.DOChannels.CreateChannel("Exhaust Valve", string.Empty, ChannelLineGrouping.OneChannelForEachLine);

 

bool[,] valueArray = new bool[3, 1];

valueArray[0, 0] = true;   // Only want to change this value.

valueArray[1, 0] = false;  // Not this value!

valueArray[2, 0] = false;  // Or this value!

 

var writer = newDigitalMultiChannelWriter(this.digitalOutputTask.Stream);

writer.WriteSingleSampleMultiLine(true, valueArray);

 

While this code works well, it requires that the values for all three valves be sent simultaneously.  I was wondering if there is DAQmx syntax that will allow changing the value associated with one valve only (i.e. the value of one valve will change and the value of the remaining two valves will remain the unchanged)?

 

Thanks!

Chris

 

 

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

Hi Chris,

 

The way the DAQmx syntax is set up, you can't write to the three digital lines individually. We do have a couple high-speed DIO cards that can enable this functionality, but the 6009 can't do that. In order to write a new output to one channel of a task, you must write a new value to all channels of a task. 

 

Regards,

 

Alexandra Valiton

National Instruments
Applications Engineer
0 Kudos
Message 2 of 7
(3,959 Views)

Is there a reason that you must add all three lines to the same task?  If you'd like to be able to write each line individually, you can create a different task for each line.  As Alexandra mentioned, DAQmx will expect all lines grouped in a single task to be written at the same time.

 

Dan

0 Kudos
Message 3 of 7
(3,949 Views)

Alexandra and Dan,

 

Thanks for taking the time to reply.

 

Dan, I understand the point you are making but not sure of the necessary syntax.  For example, what is the DAQmx syntax for communicating with, say, digital output 3 only?

 

Thanks,
Chris

0 Kudos
Message 4 of 7
(3,927 Views)

Hi Chris,

 

When you select the channel(s) to be included in a task, you can select, for example, "Dev1/port1/line0". I'm not exactly sure what you mean by "digital output 3", but it sounds like you want to isolate specific lines in a digital output port. 

 

Regards,

Alexandra 

National Instruments
Applications Engineer
0 Kudos
Message 5 of 7
(3,911 Views)

Chris,

 

The syntax really isn't much different.  Instead of creating a single task and adding three channels to it, you create three tasks and add a single channel consisting of a single line to each.  Each task would have a DigitalSingleChannelWriter, but instead of calling the WriteSingleSampleMultiLine method, you'd call WriteSingleSampleSingleLine.  With this scheme, you pick the appropriate writer for the line you want to update, and simply write the desired boolean value.

 

Hope that helps,

Dan

0 Kudos
Message 6 of 7
(3,902 Views)

Dan and Alexandra,

 

Your suggestion worked out well.   Thanks for the help.

 

In case other .NET develpers would like to see the code, it is as follows:

 

using System.Windows.Forms;

 

namespace DaqmxTest

{

    using NationalInstruments.DAQmx;

 

    public partial class Form1 : Form

    {

        private readonly Task supplyValveDigitalOutputTask = new Task();

        private readonly Task bypassValveDigitalOutputTask = new Task();

        private readonly Task exhaustValveDigitalOutputTask = new Task();

 

        public Form1()

        {

            this.InitializeComponent();

            this.CreateChannels();

            this.ResetChannelValues();

        }

 

        private void CreateChannels()

        {

            this.supplyValveDigitalOutputTask.DOChannels.CreateChannel("Dev2/Port0/line0", string.Empty, ChannelLineGrouping.OneChannelForEachLine);

            this.bypassValveDigitalOutputTask.DOChannels.CreateChannel("Dev2/Port0/line1", string.Empty, ChannelLineGrouping.OneChannelForEachLine);

            this.exhaustValveDigitalOutputTask.DOChannels.CreateChannel("Dev2/Port0/line2", string.Empty, ChannelLineGrouping.OneChannelForEachLine);

        }

 

        private void ResetChannelValues()

        {

            this.WriteToSupplyChannel(false);

            this.WriteToBypassChannel(false);

            this.WriteToExhaustChannel(false);

        }

 

        private void WriteToSupplyChannel(bool value)

        {

            var writer = new DigitalSingleChannelWriter(this.supplyValveDigitalOutputTask.Stream);

            writer.WriteSingleSampleSingleLine(true, value);

        }

 

        private void WriteToBypassChannel(bool value)

        {

            var writer = new DigitalSingleChannelWriter(this.bypassValveDigitalOutputTask.Stream);

            writer.WriteSingleSampleSingleLine(true, value);

        }

 

        private void WriteToExhaustChannel(bool value)

        {

            var writer = new DigitalSingleChannelWriter(this.exhaustValveDigitalOutputTask.Stream);

            writer.WriteSingleSampleSingleLine(true, value);

        }

 

        private void CheckBoxSupplyValveCheckedChanged(object sender, System.EventArgs e)

        {

            this.WriteToSupplyChannel(this.checkBoxSupplyValve.Checked);

        }

 

        private void CheckBoxBypassValveCheckedChanged(object sender, System.EventArgs e)

        {

            this.WriteToBypassChannel(this.checkBoxBypassValve.Checked);

        }

 

        private void CheckBoxExhaustValveCheckedChanged(object sender, System.EventArgs e)

        {

            this.WriteToExhaustChannel(this.checkBoxExhaustValve.Checked);

        }

    }

}

0 Kudos
Message 7 of 7
(3,839 Views)