Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read and write the same digital IO line efficiently

We are using a DAQ 6535 Digital IO board and are using the .NET classes to programmatically read/write the lines. We have a working patttern of creating a task and channel each time we need to read or write.

Examples:

private static bool ReadDigitalValue(string line)
        {
            using (NationalInstruments.DAQmx.Task digitalReadTask = new NationalInstruments.DAQmx.Task())
            {
                digitalReadTask.DIChannels.CreateChannel(line, "", ChannelLineGrouping.OneChannelForAllLines);
                DigitalSingleChannelReader reader = new DigitalSingleChannelReader(digitalReadTask.Stream);
                return reader.ReadSingleSampleSingleLine();

            }

        }

        private static void WriteDigitalValue(string line, bool val)
        {
            using (NationalInstruments.DAQmx.Task digitalWriteTask = new NationalInstruments.DAQmx.Task())
            {
                digitalWriteTask.DOChannels.CreateChannel(line, "", ChannelLineGrouping.OneChannelForAllLines);
                DigitalSingleChannelWriter writer = new DigitalSingleChannelWriter(digitalWriteTask.Stream);
                writer.WriteSingleSampleSingleLine(true, val);
            }
        }

 This is very slow and we need several orders of magnitude performance increase. We are using 3 digital lines that can be both input or output. They are either input or output at any given time and we know when to change the direction. I was assuming we would start but creating and holding on to the task but now I am not sure.

 

Do we need to create the task and channels each time we need to change the direction of a single digital line?

Can a digital line have more than one channel created? ie. one for input and one for output?

0 Kudos
Message 1 of 3
(5,076 Views)

Create the task once. Create the channel once.

 

 

0 Kudos
Message 2 of 3
(5,069 Views)
io is cheap so I'm assuming you could add more io if you need to. I would add a port of digital for writing and port of digital for reading and connect them through some interface logic to essentially be looking at the same point in your circuit. I did something like this in the past.

The trick is like the previous poster alluded to. Task creation and tear down is expensive so the goal would be to do it once. By dedicating tasks to write say port 0 and read back from Port 1 you can save the performance hit.

I can get you more details on the hardware side of you are interested. Just email me.
Grant M. Johnson
Project Engineer
LECO Corporation
Message 3 of 3
(4,927 Views)