Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Clarification of DAQmxBaseWriteDigitalU8 function

Not sure where to ask this. Please point me in the right direction if I am in the wrong place.

I have a NI USB 6501 that I am using for various tasks, both reading and writing.

It has taken me a while to get writing working as expected and I think it is because of a lack of understanding of the relationship to tasks, channels and the DAQmxBaseWriteDigitalU8.

The set up I have is an opto coupler on a single line on the 6501. I want to be able to turn a single device on and off, but may extend it to more later. For testing I wanted to send all the lines (24) high and low.

I started with the example code writeDigMultiplePorts.c This code sets up one task, 3 channels, creates a 3 byte buffer and makes a single write call.

This didn't do anything, none of the lines went high. If I set the numSampsPerChan in the write function to 3 the lines went high (when I wrote 255) but then I couldn't get the lines low again (when sending 0) But, when I sent another the 255 the lines momentarily went low before going high again.

I struggled with various combinations of buffer sizes, auto start values and numSampsPerChan with no change until I changed the code to only create one channel. Then everything worked as expected. I can turn the device on and off as expected.

So my question is, what is the relationship between channels, output data and the numSampsPerChan parameter to the DAQmxBaseWriteDigitalU8 function? What parameters would I need to switch arbitrary lines on the device?
0 Kudos
Message 1 of 4
(3,329 Views)
Hi henrynz,

This question seems to be discussed in another thread. To summarize, when selecting multiple ports for one task, the number of lines in the channel is multiplied by the number of ports. Normally if the port is 8 bits, three ports will be 24 bits. The problem seems to be the use of the DAQmxBaseWriteDigitalU8 function. This will only write 8 bits to the channel. For some reason an error is not being generated. Try using the DAQmxBaseWriteDigitalU32 function.

Regards,
Kent
Applications Engineer

0 Kudos
Message 2 of 4
(3,309 Views)
It's a little frustrating that the sample code is wrong.
So are you saying what I saw with all the lines going high shouldn't have happened? Should I have got an error instead?
What is the numSampsPerChan parameter for?
How does it relate to the buffer that is passed into the function?
0 Kudos
Message 3 of 4
(3,287 Views)
Hi henrynz,

I'll look into the example program a little more and recommend changes if necessary. The example that I looked at was using the
DAQmxBaseWriteDigitalU32 function and passing an array of U32 to it. There should not be an error there. The numSampsPerChan tells the function how many samples per channel to write to the card. In this case since it is set up for static digital output, only 1 sample is sent per channel. Because there are 3 ports, an array of 3 samples are inputted into the function.

Regards,
Kent
Applications Engineer
0 Kudos
Message 4 of 4
(3,256 Views)