| Customize Help

Steps to create a user-defined MIL function

The following steps provide a basic methodology for using the MIL Function Development module to create a C-based user-defined function:

  1. Create a master function. The name that you will use to call the user-defined MIL function from an application is the same as the name of the master function.

  2. Allocate a function context for the new function using MfuncAlloc(). The MfuncAlloc() function should be the first MIL function called in the master function. The allocated function context provides a MIL identifier for your user-defined MIL function, and allows this function to be treated as a regular MIL function (for example, error checking and tracing will be performed).

  3. Register the parameters of the master function in the function context using MfuncParam() with the appropriate data type or using one of the type-specific versions of this function (for example, MfuncParamMILInt()). Registering the parameters gives the slave function access to the parameter values.

  4. Call the slave function from the master function, using MfuncCall(). The slave function must be created as a separate function. Note that you must call MfuncCall() from the same thread as MfuncAlloc().

  5. Free the function context. At the end of the master function, the created function context must be freed, using the MfuncFree() function. This should be the last MIL function called in the master function. Note that you must call MfuncFree() from the same thread as MfuncAlloc() and MfuncCall().

  6. Create the slave function. This function must accept the MIL identifier of the function context as its only parameter. See the description of MfuncCall() for a prototype of a slave function. In the slave function, you must recuperate the values of the parameters registered in the master function, using MfuncParamValue(), and develop the code that will produce the required results. You can make calls to other MIL functions from the slave function.

Once you have performed the steps listed above, the user-defined MIL function is created, and you can use it in an application.

The steps required to create a script-based user-defined function are similar to creating a C-based user-defined function. So with the exception of one section, the remainder of this chapter will discuss creating a C-based MIL user-defined function. Then, the differences between the two sets of steps are examined in the Script-based user-defined MIL function section later in this chapter.

The following example shows how to create a C-based user-defined MIL function.