From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

make USB-6001 digital output always high or low in C

Solved!
Go to solution

Hello all,

 

I am new to the NI DAQ interface. I have an USB-6001 and I am trying to use this device to control some logic circuit in C. So what I want to do is:

 

* set some digital output lines to high or low levels, and change their status when needed (in C).

 

I have tested the device in NI MAX -> Test Panels, and found that the device is able to do this. Then I try to do it in C. I hace checked the examples, and the function I should use is the one called "DAQmxWriteDigitalU32". I have problem in understanding its input parameters. I have tried something with my own understanding, but it does not work as I expected. Here is one test I did:

 

uInt32   data=1;

int32 written;

TaskHandle taskHandle=0;

DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateDOChan(taskHandle,"Dev1/port0/line7","",DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxStartTask(taskHandle));
DAQmxErrChk (DAQmxWriteDigitalU32(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,&data,&written,NULL));

taskHandle=0;
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateDOChan(taskHandle,"Dev1/port0/line0","",DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxStartTask(taskHandle));
DAQmxErrChk (DAQmxWriteDigitalU32(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,&data,&written,NULL));

 

I want to simply set "Dev1/port0/line7" and "Dev1/port0/line0" to high level, but only "Dev1/port0/line0" responds me. The second parameter of the function DAQmxWriteDigitalU32 corresponds to numSampsPerChan. If i replace it (currently 1) with a larger value, e.g. 100, I can see that "Dev1/port0/line7" sends a number of 1 out, then return back to 0. So I guess the problem is just that I do not understand well all parameters of the function DAQmxWriteDigitalU32. Can anyone please tell me how I can set a digital output line to 1 or 0? 

 

Thanks!

 

Hongkun

 

0 Kudos
Message 1 of 3
(5,023 Views)

Hello,

 

Here is a link explaining the inputs of function:

 

http://zone.ni.com/reference/en-XX/help/370471W-01/daqmxcfunc/daqmxwritedigitalu32/

 

Also here you can find a lot of examples in ANSI C

 

http://www.ni.com/example/6999/en/

 

 

Randy @Rscd27@
0 Kudos
Message 2 of 3
(4,991 Views)
Solution
Accepted by topic author Hongkun

Hi,

I finally figure out how to do that! The function works fine, and my problem was not setting the value of data to be written correctly. It seems that if I want to write a 1 to port0/line1, I need to put "data = 2^1" rather than "data = 1", because by default it is the second bit of the port. Similarly, "data = 2^7" for a high level in port0/line7. I find this setting is surprising when you want to control an individual line. It sounds more reasonable when you control the whole port. Anyway, the problem is solve!

Thanks anyway!

Hongkun

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