LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Which function do I use to write binary data to ports/lines?

I want to turn on (write 1) to P0.0 and P0.1. I've found two functions that are likely candidates: DAQmxWriteBinary() and DAQmxWriteDigital(). What's the difference? 

 

Both of these functions require an array argument (WriteArray) to specify the output. Seems like a single 8-bit binary number with the correct bit pattern should turn on the desired lines. Why do the functions require arrays of numbers instead of a single binary number?

 

Which function should I use and how do I set WriteArray to turn these lines on?

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

This code should work:

 

uInt8   x[2];

x[0] = 1; x[1] = 1;
DAQmxChk (DAQmxCreateTask ("", &taskH));
DAQmxChk (DAQmxAddGlobalChansToTask (taskH, "Dev1/port0/line0:1"));
DAQmxChk (DAQmxStartTask (taskH));
DAQmxChk (DAQmxWriteDigitalLines (taskH, 1, 1, 10, DAQmx_Val_GroupByChannel, x, &written, 0));



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,118 Views)

Roberto,

 

Your solution works great but I don't know why. What do the bits in each element of array x[] represent? Is bit 0 the only one that matters? Or are the other bits significant? This doesn't seem to be described very clearly in the help text.

 

thanks!

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

I'm not trying to be rude here and tell you to "RTFM" but you really have to read the function panel help and the help on each input control. (Right click the panel for the panel help, the control for the control help). The help for those functions explains all of what you want to know.

 

Most of the function help is pretty good, it's a resource you should turn to prior to posting in the forum.

 

But to answer your question without going into all the details, the arrays are there to provide multiple samples out each DIO port. If you want to send a data pattern, you set it up in the array, tell the function how many samples there are and configure the timing.

Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
0 Kudos
Message 4 of 4
(3,078 Views)