11-13-2020 06:45 AM
Hi, I'm new to the community. Sorry for my english. I'm trying to learn the basics, but in the examples I saw from labwindows, I don't understand them.
I'm trying to do the basics, reading and writing digital and analogic with the DAQmx functions, and I didn't want to depend on a button on the panel, I would like it to be like a scan.
I am using NI USB6216. The code below is what I'm trying to do at first with the reading of a button and then turn on a led when activated, I know there's a lot wrong, but I'm not able to see something basic on the internet
#include <ansi_c.h>
#include <cvirte.h>
#include <userint.h>
#include "teste03.h"
#include "toolbox.h"
#include <NIDAQmx.h>
#include <DAQmxIOctrl.h>
//==============================================================================
// Constants
//==============================================================================
// Types
//==============================================================================
// Static global variables
static int panelHandle = 0;
//==============================================================================
// Static functions
//==============================================================================
// Global variables
TaskHandle daqTask = 0;
TaskHandle daqTaskOut = 0;
int32 read,bytesPerSamp;
//char chan[256];
//==============================================================================
// Global functions
/// HIFN The main entry-point function.
int main (int argc, char *argv[])
{
int error = 0;
uInt8 data[100];
uInt8 data1[8] = "";
/* initialize and load resources */
nullChk (InitCVIRTE (0, argv, 0));
errChk (panelHandle = LoadPanel (0, "teste03.uir", PANEL));
/* display the panel and run the user interface */
errChk (DisplayPanel (panelHandle));
errChk (RunUserInterface ());
while(1)
{
DAQmxCreateTask("TesteDI",&daqTask);
DAQmxCreateDIChan(daqTask,"Dev1/Port1/line0:7","TesteDI",DAQmx_Val_ChanForAllLines);
//DAQmxLoadTask("TesteDI", &daqTask);
DAQmxStartTask(daqTask);
DAQmxReadDigitalLines(daqTask,1,10.0,DAQmx_Val_GroupByChannel,data,100,&read,&bytesPerSamp,NULL);
if(data == 1)
{
DAQmxCreateTask("D1_1",&daqTaskOut);
DAQmxCreateDOChan(daqTaskOut,"Dev1/port1/line0:7","D1_1",DAQmx_Val_ChanForAllLines);
//DAQmxLoadTask ("MyDigitalOutTask", &daqTaskOut);
DAQmxStartTask(daqTaskOut);
DAQmxWriteDigitalLines (daqTaskOut, 1, 1, 10.0, DAQmx_Val_GroupByChannel, data1, NULL, NULL);
DAQmxStopTask(daqTaskOut);
DAQmxClearTask(daqTaskOut);
}
//DAQmxStopTask(daqTask);
//DAQmxClearTask(daqTask);
}
Error:
/* clean up */
if (panelHandle > 0)
DiscardPanel (panelHandle);
return 0;
}
//==============================================================================
// UI callback function prototypes
/// HIFN Exit when the user dismisses the panel.
int CVICALLBACK panelCB (int panel, int event, void *callbackData,
int eventData1, int eventData2)
{
if (event == EVENT_CLOSE)
QuitUserInterface (0);
return 0;
}
11-18-2020 10:51 PM
The way the code works is that Main() will run until it hits this line
errChk (RunUserInterface ());
You will see that the GUI is open and running. The program will sit in RunUserInterface() until you close the GUI. So your DAQmx code won't get run until you close the GUI.
If you want to have the DAQmx code running in parallel with the GUI then you probably want to create a separate thread and have the DAQmx code run on that thread. Look up ThreadFunctions in the CVI help menu. There is example code to get you started.
If you don't know where the examples are, you can get to them by opening up CVI, and at the splash screen, clicking on 'examples.'