LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Control of USB-6008OEM1 board does not work unless the Measurement and Automation Explorer, Test Panel "Start" button is clicked

Solved!
Go to solution

The following code is being used to control a USB-6008OEM1 board, the code works, but, if the board is powered down then back on, this code does not work until the Measurement and Automation Explorer, Test Panel "Start" button is clicked.  

 

For example, the code below is standard code to set digital outputs.   The output is not set until the Measurement and Automation Explorer, Test Panel "Start" button is clicked.

 

I am curious what functionality does the "Start" button perform.

 

Specifically, using the NIDAQmx.lib and NIDAQmx.h in this C++ code example, does anyone know what API equivalent calls is being used when the "Start" button is clicked?

 

Here is the sample code (very basic):

 

void DigitalOut(int line, bool on)
{
 TaskHandle h(0);
 int32 nErr = DAQmxCreateTask("Digital Output Task", &h);
 char szTerminal[256];
 sprintf_s(szTerminal, 256, "/Dev1/port0/line%d", line);
 
 uInt8 nData = 0x00;
 int error(0);
 uInt8 data[1];
 data[0] = (on == true) ? 1 : 0;
  
 int32 numSampsPerChan = 1; 
 bool32 autoStart = 0; 
 float64 timeout = 10;
 bool32 dataLayout = DAQmx_Val_GroupByChannel; 
  
 DAQmxCreateDOChan(h, szTerminal, "write digital out", DAQmx_Val_ChanPerLine);
 DAQmxStartTask(h);
 int32 nDOErr = DAQmxWriteDigitalLines(h, numSampsPerChan, autoStart, timeout, dataLayout, data, NULL, NULL);
 DAQmxStopTask(h);
 DAQmxClearTask(h);
}

 

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

It looks like the DAQmxStartTask may not be configured with the proper TaskHandle for your code.

 

This document will explain the configurations for these functions.

http://www.ni.com/tutorial/5409/en/#toc3

Niki Budgell | Product Planner - SW Management | NI
0 Kudos
Message 2 of 5
(3,486 Views)
Solution
Accepted by topic author big.tuna

Niki,

Could you explain your response please.  Notice the code is using "h" as the handle in all cases in the code above.  BTW, I have since found a solution so we can close this, but the code above does work as-is. Furthermore, I am still curious if anyone knows what code runs under the "Start" button as described in my original post.  The "workaround" uses a wrapper initialization routine that flips the digital state on all lines.   The full explanation is more complicated and depends on the full system which has devices connected to the digital output lines, which also has LEDs to show the state.   The problem has something to do with the way the board keeps the previous state when de-powered.   Upon power up the connected LEDS (in my system) show all lines are false, so when I set the pattern to debug and it did not appear to work in fact it was due to the fact that I was setting the lines to the same state so nothing changed on the output LEDs.   I added initialization code to first read the line, set it to the opposite state, then proceed as needed, this works with the code above as-is, so the handle is fine.   Thank you for the help.

 

 

0 Kudos
Message 3 of 5
(3,481 Views)

Hello,

 

I am glad that you were able to get your code running.

 

My response was to the way the Task Handle is configured (TaskHandle h(0)).  This notation is not something I have seen when using this API.  The article in my previous post details how I would go about configuring the task in this API.

Niki Budgell | Product Planner - SW Management | NI
0 Kudos
Message 4 of 5
(3,456 Views)

Niki,

Thanks, that notation is C++, nothing to do with the NI API.  For example, the TaskHandle is defined using a typedef as:

typedef void* TaskHandle;

The notation:

TaskHandle h(0)

uses the C++ initializer, which in this case is identical to the two-stage construction of trivial memory allocation followed by assignment, but the notation is cleaner and generally preferred.

I am still curious as to what is going on under the hood with the "Start" button in the Measurement and Automation Explorer.

 

 

0 Kudos
Message 5 of 5
(3,431 Views)