Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write DO lines respectively?

Solved!
Go to solution

Hello,

I have a PCI-6509 card and I want to control any of those 96 lines in real time.

I just take the first 4 DO for example.

 

            digitalWriteTask = new Task();
            digitalWriteTask.DOChannels.CreateChannel("Dev2/port1/line0:3", "myDOChannel",
                        ChannelLineGrouping.OneChannelForEachLine);
            myDigitalWriter = new DigitalSingleChannelWriter(digitalWriteTask.Stream);

It seems impossible to change line1 without interferencing other three lines since we need a bool[4] on the writer.

Read and Write is not an option in my case. Do I really have to create 96 Tasks and DO channels to be able to control these 96 lines separately? Is there any other way? 

 

0 Kudos
Message 1 of 4
(3,333 Views)

Hi JoeGoz,

 

I think the best way to go about this is to keep the state of all of the digital lines in memory and write functions that can change just one value.

 

Here's an example function that can set the value of one single line:

 

private Boolean[] setLine(int line, Boolean[] lines, Boolean value_to_set)
{
    lines[line] = value_to_set;
    return lines;
}

And here's an example of how you'd use this with your digital writer:

Boolean[] lines = new Boolean[96];
myDigitalWriter.WriteSingleSampleMultiLine(true, setLine(0, lines, true));

This is a quick example, but you can develop a more robust way to write these values. This will let you avoid creating a separate task for every single line.

 

Cheers,

Ryan C.

0 Kudos
Message 2 of 4
(3,307 Views)

Thank you Ryan, but keep a single state table for all digital lines here may brings me other problems. This method is not thread-safe,and I need to control them in a very fast sequence. 

e.g,while I am doing this in thread #1:

 

for(int i = 0; i < 10; i++)
    lines[i] = value;

thread 2#:

 

 

myDigitalWriter.WriteSingleSampleMultiLine(true, setLine(0, lines, true));

Then the operation result of the second can be unknown. I need to implement lock for this,but it will make async weak.

If I really have to go with 96-task, does it somehow influence the performance? I'm not sure if multi-task would draw back the system speed(on card or on software).  If not, then I guess that will be a proper way.

 

0 Kudos
Message 3 of 4
(3,294 Views)
Solution
Accepted by JoeGoz

Hi JoeGoz,

 

I believe that most of the effect you'll see on performance will be in memory, not CPU usage for this. I don't think this would have too much of an effect, but I'd give it a try with a lower number of tasks (like 10 of your lines) and see if you end up with a huge memory spike.

 

It will also be useful to start your tasks once you create them to increase performance. Take a look at the DAQmx Task State Model:

 

http://zone.ni.com/reference/en-XX/help/370466AD-01/mxcncpts/taskstatemodel/

 

If your tasks are already in the running state, they will not have to transition through this each time you write to a digital line. Use this function to start all of your tasks after you create them:

 

DAQmxStartTask(myDigitalWriter);

If you don't want to go for the 96-tasks, I would also think about coming up with a way to just write that state table asynchronously instead of the actual task. That way if you try to set two digital lines at almost the same time, you can just write both of those out at the same time instead of calling the DAQmx write function twice. You'll be able to improve your async a lot if you only need to lock writes to the array.

 

Cheers,

Ryan C.

0 Kudos
Message 4 of 4
(3,278 Views)