Here´s the *.c-file of read digital line
#include <ansi_c.h>
#include <NIDAQmx.h>
#define DAQmxErrChk(functionCall) {DAQmxError = (functionCall); {if (DAQmxError < 0){goto Error;}}}
int32 CreateDAQTaskInProject(TaskHandle *taskOut1)
{
int32 DAQmxError = DAQmxSuccess;
TaskHandle taskOut;
DAQmxErrChk(DAQmxCreateTask("DAQTaskInProject", &taskOut));
DAQmxErrChk(DAQmxCreateDIChan(taskOut, "Dev2/port0/line0",
"DigitalIn0", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute(taskOut, "DigitalIn0", DAQmx_DI_InvertLines,
0));
DAQmxErrChk(DAQmxCreateDIChan(taskOut, "Dev2/port0/line3",
"DigitalIn1", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute(taskOut, "DigitalIn1", DAQmx_DI_InvertLines,
0));
*taskOut1 = taskOut;
Error:
return DAQmxError;
}
Here´s the *.h-file
int32 CreateDAQTaskInProject(TaskHandle *taskOut1);
#ifdef __cplusplus
}
#endif
#endif // ifndef DAQTASKINPROJECT_INCLUDE
Then later you put the *.c-function in your main *.c like here:
#include <nidaqmx.h>
#include <cvirte.h>
#include <userint.h>
#include "DAQAssistantExercise.h"
#include "DAQTaskInProject.h"
static int panelHandle;
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "DAQAssistantExercise.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK AcquireCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int32 read;
float64 data[100];
TaskHandle taskHandle;
switch (event)
{
case EVENT_COMMIT:
CreateDAQTaskInProject(&taskHandle); // Here is open the function of the *.c file with the digital line Task
DAQmxReadAnalogF64 (taskHandle, DAQmx_Val_Auto, 100.0,
DAQmx_Val_GroupByChannel, data, 100, &read, 0);
DeleteGraphPlot (panel, PANEL_GRAPH, -1, VAL_IMMEDIATE_DRAW);
PlotY (panel, PANEL_GRAPH, data, 100, VAL_DOUBLE, VAL_THIN_LINE,
VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
DAQmxClearTask (taskHandle);
break;
}
return 0;
}
int CVICALLBACK QuitCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}