Custom Functions

Custom functionality provided by your adaptor that is not part of the standard session-based interface can be exposed to MATLAB via the DAQ SDK custom interface. For example, your device might provide an on-board power supply.

Note

This topic assumes experience writing MEX-files.

To add a custom function, first review the custom functions available in the demo adaptor in the folder matlabroot\matlab\toolbox\daq\daqsdk\+daq\+demoadaptor\+custom. The installed files in this folder are:

testHasInputsHasOutputs.m
testHasInputsNoOutputs.m
testNoInputsNoOutputs.m
testThrowCustomExceptions.m

Use these steps to create your own custom function:

  1. Add a function to the MyDriver class (MyDriver::customFunction).

  2. Add a function to the MyAdaptor class (MyAdaptor::customFunction) that calls MyDriver::customFunction with the designated:

    • Inputs

    • Outputs

    • Custom error code

  3. Update custom_my.cpp to:

    • Define a function to call (dispatch) the custom adaptor function MyAdaptor::customFunction.

    • Update the customizeMap function to add:

      functionMap["myCustomFunction"] = customFunction;

      where customFunction is the name of the MEX-function that calls MyAdaptor::customFunction, and myCustomFunction is the name of function in MATLAB.

  4. Define your custom MATLAB function myCustomFunction.m in the +daq\+myadaptor\+custom subpackage for your adaptor.

    • Choose the appropriate template from \+daq\+demoadaptor\+custom\ to copy and rename.

      • Has Inputs, Has Outputs

      • Has Inputs, No Outputs

      • No Inputs, No Outputs

    • Rename the file to perform the desired function, for example, myCustomFunction.m.

    • Edit myCustomFunction.m to

      • Update: functionName = 'myCustomFunction';

      • Provide the inputs to the function as a structure.

For functionality that is not part of the standard session interface, contact MathWorks® technical support at https://www.mathworks.com/support/contact_us to let us know what functionality you need.

Related Topics