Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI DAQmx Base w/ USB 6008 writing to multiple digital output ports

I have been unable to control all 12 of lines of the USB 6008 at the same time. I've tried two main methods: (1) writing separately to each port and (2) using the digital multiple write to write to both ports at the same time. Method (1) results in the port that is not being written to being reset to 1. Method (2) only sets one of the ports.

 

In more detail, this what I've so far:

 

(1) I initially tried using the example writeDigPort.c to write to port0 and then to port1 (I updated the bytes to write to be 0x00); however, when I write to port1, everything all the digitial outs on port0 get reset to 1 (high, 5v) (the write works, though). Similarly, if I write to port0, all the digital outputs on port1 get go high (5v).

 

(2) I realized that the writeDigPort function was writing a uint32, not an uint8, since the usb 6008 only has 8 lines on port0 and 4 on port1 (even though the documentation indicated that this shouldn't be a problem). I updated the function to use DAQmxBaseWriteDigitalU8, and changed w_data to a uInt8. I still encountered the same problem. I've attached my modified writeDigPort.c code.

 

At this point I gave up on writing 8 bits at a time, and instead switched to the writeDigMultiplePorts.c program.

 

(3) Initially I modified the code such that the num_ports variable = 2 and commented out all references to chan3. I encountered a different behavior this time: only port0 was modified. 

 

(4) I figured the first cause of this was the mismatch in sizes, once again, the writeDigMultiplePorts.c function writes and uses a uInt32. I changed the w_data type to uInt8 and the DIO write function to DAQmxBaseWriteDigitalU8. I ran the code again, and the only bits that changed were the port0 bits. I've attached this modified code (writeDigMultiplePorts.c).

 

(5) On a limb, I decided to see what happened if I increased the numSampsPerChannel parameter to 2. Running this code set all lines on port0 and port1 to zero, even though sizeof(w_data) == 2. I didn't expect this to work, and it didn't.

 

Any suggestions on how to control at 12 lines at the same time?

 

Am I going about this the completely wrong way? Or is something else going on?

 

I'm using NI DAQmxBase 3.3 for linux (2.6.29-gentoo-r6).

 

Thank You,

  Marek

Download All
Message 1 of 5
(5,453 Views)

Hi Marek,

 

The reason that the un-accessed port would be set to high, is because the USB 6008/9 devices have an internal 4.7kOhm pull-up resistors that drive the line high when nothing is connected, as seen in the manual.

 

As for setting up the output, I was successful in writing to all 12 lines, although it does require a little work.  I was able to setup my channel as dev1/port0:1, which makes both ports in the line.  I then chose to use DAQmxBaseWriteDigitalU32, and set my binary data string as "101010101010" which corresponds to 12 lines, alternating high and low.  I was able to bring in the data and verify that the lines indeed alternated. 

 

Please let me know if this works out for you.

 

Best,

Adam
Academic Product Manager
National Intruments
Message 2 of 5
(5,417 Views)

Hi Adam,

 

Thanks for your response. With your help and a little bit of luck, I was able to successfully write to all 12 of the digital output lines at the same time. However, I'm still slightly baffledby the behavior of the device/or the interface. To get the system to work I essentially used the following lines of code:

 

char         chan1[] = "Dev1/port0:1";

uInt16       w_data [2];

 

DAQmxErrChk (DAQmxBaseCreateTask ("", &taskHandle));
DAQmxErrChk (DAQmxBaseCreateDOChan(taskHandle,chan1,"",DAQmx_Val_ChanForAllLines));

 

w_data[0] = 0x4321;
w_data[1] = 0x8765;

 

 DAQmxErrChk (DAQmxBaseWriteDigitalU8(taskHandle,2,1,10.0,DAQmx_Val_GroupByChannel,(uInt8*)&w_data[0],&written,NULL));

 

This writes hex 7 to port1 (lines 0:3), and hex 65 to port0 (lines 0:7). This seems very odd: shouldn't DAQmxBaseWriteDigitalU8 write only 8 bits at a time (even if I've opened 12 ports)? Furthermore, if I only change the second to the DAQmxBaseWriteDigitalU8 to 1, port1 doesn't change and hex 34 gets written to port0. I'm baffled by this behaviour. Any ideas why?

 

Thanks!

Message 3 of 5
(5,398 Views)

A minor typo in the last paragraph: ... *second argument to DAQmxBaseWriteDigitalU8 to 1...

 

The corrected paragraph: 

 

This writes hex 7 to port1 (lines 0:3), and hex 65 to port0 (lines 0:7). This seems very odd: shouldn't DAQmxBaseWriteDigitalU8 write only 8 bits at a time (even if I've opened 12 ports)? Furthermore, if I only change the second* argument to DAQmxBaseWriteDigitalU8 to 1, port1 doesn't change and hex 34 gets written to port0. I'm baffled by this behaviour. Any ideas why?

0 Kudos
Message 4 of 5
(5,389 Views)

Hi Marek,

 

DAQmx should write the data using the least significant bit format, which would start at port1:line3.  With that said, I would recommend using a U16 to control both ports if they are in the same digital output task, or you could create 2 tasks in parallel, and have them update at the same rate in software.  The 6008/9 cards are static DIO, so this will work out fine and they will output at the same time.  Then you will be able to write a direct value to each port, and directly control the ports with a byte of data each time.

 

Best,

Adam
Academic Product Manager
National Intruments
0 Kudos
Message 5 of 5
(5,356 Views)