Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

USB-6008 DIO Lines...

I have a USB-6008 that I'm using to develop an application with. The development language used is C# (.NET 2003 with Measurement Studio 7.0). Right now, I have the device successfully reading from the counter input. Since this program reads rising edges from the counter input, I can get the frequency of the input signal and cause something to happen should the frequency rise above a certain threshold.

I'm trying to use the Digital port (port0) to set line 0 high if a condition has been met. I can do this when I select 'Dev1/port0' - I get Port 0 line 0 to go high or low. The problem is that I want to have control over lines 1, 2, 3, 4, 5, 6 and 7 - I only have access to line 0 right now on either Port 0 or Port 1.

Currently I'm using the following imported functions from the C samples included in the NI-DAQmxBase software:

int result = DAQmxBaseCreateTask("", out dioTaskHandle); // create the DIO task...
result = DAQmxBaseCreateDOChan(dioTaskHandle, "Dev1/port0", "", 1); // create DIO channel...
result = DAQmxBaseWriteDigitalScalarU32(dioTaskHandle, true, 1.0, 0, out reserved); // write a 0 to the channel selected

Just a note about the third line of code - the documentation states that parameter 2 of the 'DAQmxBaseWriteDigitalScalarU32()' function must be set to false. When I use false as the 2nd parameter, I end up getting a return value of -1073807346. I can't find what that error is in any documentation. So, I set this value to true - and it works (I get a return value of 0 meaning success).

In my development cycle, I've tested for ways to get access to a single line (other than line 0), and found that when I create a DO channel with the value "Dev1/port0", port 0 line 0 is active. When I create a DO channel with the value "Dev1/port1", port 1 line 0 is active. If I try to create a DO channel with a value of "Dev1/port2" through "Dev1/port7", I get a return value of -200170 (Physical Channel Does Not Exist). The documentation isn't very clear on the ports and single lines for digital output.

My question is - how can I gain access to ALL of the lines of a particular port?

Thanks,
tsc
0 Kudos
Message 1 of 2
(3,298 Views)
I just figured out the lines of the port - of course this will happen once I've posted a question. If others run into the same type of problem, here's how to access each individual line of a selected digital port:

line 0 - 0x01 (binary: 0000 0001)
line 1 - 0x02 (binary: 0000 0010)
line 2 - 0x04 (binary: 0000 0100)
line 3 - 0x08 (binary: 0000 1000)
line 4 - 0x10 (binary: 0001 0000)
line 5 - 0x20 (binary: 0010 0000)
line 6 - 0x40 (binary: 0100 0000)
line 7 - 0x80 (binary: 1000 0000)

all lines off - 0x00 (binary: 0000 0000)
all lines on - 0xff (binary: 1111 1111)

// create a task...
result = DAQmxBaseCreateTask("DigitalPort0 Task", out dioTaskHandle);
// create a channel - I'm using Port 0 in this example)...
result = DAQmxBaseCreateDOChan(dioTaskHandle, "Dev1/port0", "", 1);
// turn off all digital lines to the port selected (I do this when starting up)...
result = DAQmxBaseWriteDigitalScalarU32(dioTaskHandle, true, 1.0, 0x00, out reserved);

// if I want to turn on the first line (P0.0) of port0, then I send 0x01 as the fourth parameter...
result = DAQmxBaseWriteDigitalScalarU32(dioTaskHandle, true, 1.0, 0x01, out reserved);

// if I want to turn on the fifth line (P0.5) of port0, then I send 0x20 as the fourth parameter...
result = DAQmxBaseWriteDigitalScalarU32(dioTaskHandle, true, 1.0, 0x20, out reserved);


I hope this will help someone else out using this device and Measurement Studio for .NET.
0 Kudos
Message 2 of 2
(3,291 Views)