Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

DIO can't write with WriteSingleSamplePort

I am controlling a PCI-6229 with DAQmx and C#. I have a digital output line that I am trying to write with the code:

uint data = 1;
Task outputTask = new Task("Digital output task");
outputTask.DOChannels.CreateChannel("dev1/port0/line8", "",
    ChannelLineGrouping.OneChannelForAllLines);
DigitalSingleChannelWriter dWrite = new
    DigitalSingleChannelWriter(outputTask.Stream);
dWrite.WriteSingleSamplePort(true, data);
outputTask.Dispose();


When I run this code, nothing happens. (It used to work! Then I went away and worked on something else for a while, and now that I'm back, it's stopped working.) If I replace WriteSingleSamplePort() with:

dWrite.WriteSingleSampleSingleLine(true, data == 1 ? true : false);

the line switches on and off as expected.
I would like to be able to write multiple lines using the same task, so I'd like to figure out why one method will work but not the other. Has anybody else had this happen?
0 Kudos
Message 1 of 2
(3,599 Views)

Hello Elizabeth,

It looks like the way you have configured your task is what is causing the trouble.  I noticed that you want to write to port0/line8 on your device, yet specified data as 1.  The method WriteSingleSamplePort attempts to write to an entire port at once.  Since you have specified only one line in your task, DAQmx is ignoring all of the bits that would be assigned to other lines.  In your case, a 0 will make port0/line0 go low while a 1 will make port0/line0 go high.  Since you have specified port0/line8, the changes to line0 are ignored.  If you try running your code with a number that will cause line 8 to return high (such as 128) the output value will change from low to high. 

The method WriteSingleSampleSingleLine will only affect the line configured in the CreateChannel method, so that is why this line works when you specify port0/line8. 

If you specify a group of lines when you are configuring the task (this can be done with the syntax dev/port0) all of the lines in the port will be affected when the WriteSingleSamplePort method is called. 

Regards,
Browning G
FlexRIO R&D
0 Kudos
Message 2 of 2
(3,587 Views)