11-29-2016 07:37 AM
Hello,
I would like to know how to create a function which involves multiple other funcions in it, so i could simplify my code. For example here is my issue:
/*
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateDOChan (taskHandle, "Dev2/port0/line0", "AI0", DAQmx_Val_ChanPerLine));
DAQmxErrChk (DAQmxStartTask(taskHandle));
DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,data1,NULL,NULL));
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
*/
So how could i manage to use these whole set of functions in only one? I guess i would need another .c file for that but if anyone could give me a concrete example with this, i would appreciate that.
Thank you in advance!
Solved! Go to Solution.
11-29-2016 10:41 AM
Despite the fact that those functions pertain to DAQmx driver, there is nothing special with them so you can create your own function where to put them and call it wherever you need it.
As an example:
int MyDigitalOutputFunction (void) {
// Declare variables used in the function
taskHandle
data1
error
// Assign values to data1 if not received from the caller
data1
// DAQmx instructions DAQmxErrChk (DAQmxCreateTask("",&taskHandle)); DAQmxErrChk (DAQmxCreateDOChan (taskHandle, "Dev2/port0/line0", "AI0", DAQmx_Val_ChanPerLine)); DAQmxErrChk (DAQmxStartTask(taskHandle)); DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,data1,NULL,NULL)); DAQmxStopTask(taskHandle); DAQmxClearTask(taskHandle);
Error:
return error; }
Once completed, the above function will set the digital output and return the error found in the function. You will need to declare the function (either directly in the source file or in a global include file you may have designed) before you can call it in your code.
From this point on you may want to modify the function passing some data to it to permit reusing it with other parameters, e.g. the digital line to drive, the value to assign to it... it depends on how you want to use this function throughout your program.
As you can see there is nothing special in this job, so don't let DAQmx scare you and go on designing your application!
12-01-2016 05:41 AM - edited 12-01-2016 05:41 AM
Thank you very much for your help and quick response!