LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

multiple functions in one function

Solved!
Go to solution

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!

 

0 Kudos
Message 1 of 3
(2,791 Views)
Solution
Accepted by topic author Kugelkopf

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! Smiley Wink



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,772 Views)

Thank you very much for your help and quick response!

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