09-20-2022 06:10 AM
Hi all,
Need a recommendation for the following.
I have the next DO lines from a configuration file:
Pump1, Dev1/port0/line6
Pump2, Dev1/port0/line7
Pump3, Dev1/port1/line3
Valve1, Dev1/port1/line1
Valve2, Dev1/port1/line2
Valve3, Dev1/port1/line0
So, two ports and some lines. I want to control the DO lines individually. What is the recommended way to go?
All separate tasks with their corresponding writers seem a bit overkill here.
An array of 6 booleans in this case? How to deal with the lines that are not to be changed?
bool[] arr = new bool[6];
arr[line] = linevalue;
this.digitalOutwriter.WriteSingleSampleSingleLine(true, arr);
Looking forward for some suggestions!
Thanks a lot!
Martin
09-21-2022 10:19 PM
Use the multiple line version of write and you've to keep track of the last written values for all lines, update with new values for required lines and write all lines.
09-29-2022 02:00 AM
Hi,
Thanks for your suggestion. This came up to me as well ;), but you have to memorize last written values. I hoped that this kind of bookkeeping was arranged by DAQmx.
I worked arround it by using instant creation of a Task and a Writer when a line (bit) must be changed:
using (Task task = new Task())
{
task.DOChannels.CreateChannel(ch, "", ChannelLineGrouping.OneChannelForEachLine);
DigitalSingleChannelWriter digitalOutWriter = new DigitalSingleChannelWriter(task.Stream);
digitalOutWriter.WriteSingleSampleSingleLine(true, value);
}
where: ch="Dev1/port0/lineXX"
I do not know what the performance will be, but in my case the digital out lines need no high frequencies.
Greetz
09-30-2022 09:46 AM
Hi MVW,
First of all let me know witch hardware your are using to be more clear understandable.
Also tell me in witch programming language you wrote this code, I guess it might be Measurement studio.
And if it's not problem can you describe more clear what do you want to do with those DO lines?
Regards )
10-03-2022 01:33 AM
Ofcourse. I am using C# in Visual Studio 2019 using the latest 2022 Q3 DAQmx libraries. At the moment the NI USB-6008 hardware must be supported, but as far as I know is the DAQmx generic for al their products. As said, the DO lines are used to control valves and pumps and therefore does not have to be high frequent signals. Performance is not an issue here.
Cheers
10-03-2022 09:12 AM
@MVW wrote:
Ofcourse. I am using C# in Visual Studio 2019 using the latest 2022 Q3 DAQmx libraries. At the moment the NI USB-6008 hardware must be supported, but as far as I know is the DAQmx generic for al their products. As said, the DO lines are used to control valves and pumps and therefore does not have to be high frequent signals. Performance is not an issue here.
Cheers
If performance is not an issue, create 1 task per DO channel, and do not configure DAQmx timing (this tells the task to work in software timed i.e., whenever you send data). Based on what channel you need to change index the appropriate task and write data. Note, you cannot change the state for multiple DO lines at the exact time (but a few uS apart sequentially). No need to create and clear the task repeatedly, just create once and clear at the end once.