LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQ

Hello Everyone!

I am new to LabWindows/CVI and i would like to ask for help.I am working on a project with a NI USB DAQ 6001 device. I need to acquire more signals than i have inputs on my device (8 analouge inputs). I am using multiplexers to sort this problem out. As i have 13 digital I/O channels i would use them to control my multiplexers to change the multiplexers channels so i can do signal acquisition on the same analogue input channel. However i don't know how to do it in CVI. I looked for help in the libraries and other texts. I have found DAQ Assistant, in which you can create your application without programming, but i don't know where to download it or get it, I only have CVI and NI MAX.

My question here is : Can someone show me a concrete example in which you create and control digital output channels on a DAQ device and start signal acquisition on an analouge input channel. I would like to also know how to implement delays in my code so that the program automatically switches the multiplexers' channels while setting the D/O channels.

Other question : Is there a source to download DAQ assistant in which i can create my application in a graphical user interface then translate it to CVI code?

Thank you in advance!

0 Kudos
Message 1 of 3
(2,758 Views)

The DAQ assistant is already present in your system once you have installed DAQmx with the support for CVI IDE: to start it you simply have to execute Tools >> Create/Edit DAQmx Tasks menu function.

 

Regarding your actual question, the DAQ assistant can help you in understanding how things works for the individual parts of the complete app (analog measurement and digital output) but it is limited when coming to integrating the two together. The following tutorial can help you in understanding how the tool works:

Using the DAQ Assistant in NI LabWindows™/CVI™

 

I suggest you take a look at DAQmx examples installed on your system and try understanding the basic mechanisms of a DAQ process so that you can then proceed developing your application.

Examples are stored in <Public documents folder>\National Instruments\CVI\Samples\DAQmx: the basic acquisition example is in Analog In\Measure Voltage\Acq-IntClk subfolder while digital output example can be found in Digital\Generate Values\Write Dig Chan subfolder.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 3
(2,739 Views)

Thank you 

#include <windows.h>
#include <utility.h>
#include <ansi_c.h>
#include <cvirte.h>
#include <userint.h>
#include <NIDAQmx.h>
#include <DAQmxIOctrl.h>
#include "WriteDigChan.h"

#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

static int panelHandle;

int main(int argc, char *argv[])
{
if( InitCVIRTE(0,argv,0)==0 )
return -1; /* out of memory */
if( (panelHandle=LoadPanel(0,"WriteDigChan.uir",PANEL))<0 )
return -1;
SetCtrlAttribute(panelHandle,PANEL_DECORATION_BLUE,ATTR_FRAME_COLOR,VAL_BLUE);
NIDAQmx_NewPhysChanDOLineCtrl(panelHandle,PANEL_CHANNEL,1);
DisplayPanel(panelHandle);
RunUserInterface();
DiscardPanel(panelHandle);
return 0;
}

int CVICALLBACK PanelCallback(int panel, int event, void *callbackData, int eventData1, int eventData2)
{
if( event==EVENT_CLOSE )
QuitUserInterface(0);
return 0;
}

int CVICALLBACK WriteCallback(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
int error=0;
TaskHandle taskHandle=0;
char chan[256];
uInt8 data[8];
char errBuff[2048]={'\0'};
int i=0;
char analogInputs[20] ={'\0'}; ;




if( event==EVENT_COMMIT ) {
GetCtrlVal(panel,PANEL_CHANNEL,chan);
GetCtrlVal(panel,PANEL_BINARYSWITCH_0,&data[0]);


/*********************************************/
// DAQmx Configure Code
/*********************************************/
for(i; i<8; i++)
{
SetWaitCursor(1);
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));

sprintf(&analogInputs[0], "Dev2/port0/line%d", i);
DAQmxErrChk (DAQmxCreateDOChan (taskHandle, &analogInputs[0], "", DAQmx_Val_ChanPerLine));

/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));

/*********************************************/
// DAQmx Write Code
/*********************************************/
DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));

SetCtrlVal(panel,PANEL_ANAL1,"Érték");
//SetCtrlAttribute(panel, PANEL_ANAL1,CTRL_ATTR_VAL, "Érték");

Sleep(2000);

/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxErrChk (DAQmxResetChanAttribute (taskHandle, NULL, DAQmx_DO_LineStates_DoneState));



DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);


}

if(data == 0)
{
if( taskHandle!=0 ) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}

}


}

Error:
SetWaitCursor(0);
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
// DAQmxStopTask(taskHandle);
// DAQmxClearTask(taskHandle);
}
if( DAQmxFailed(error) )
MessagePopup("DAQmx Error",errBuff);
return 0;
}

*//

 

0 Kudos
Message 3 of 3
(2,733 Views)