Creating External Models (Control Design and Simulation Module)
- Updated2023-03-14
- 2 minute(s) read
Third parties can use the External Model Interface (EMI) to create an external, or third-party, model in C/C++. Refer to the Example 1: Creating an External Model topic for an example of a C/C++ project that defines an external model.
Complete the following steps to create an external model.
- Create a C/C++ project that uses the External Model Interface functions to define the dynamic equations for the external model you want to simulate. Use the following guidelines when creating the C/C++ project:
- Use C-style calling conventions when defining the Callbacks functions.
- Use the EMI_GetCurrentVersion function in the Simulation shared library NILVSim.dll, (macOS) NILVSim.framework or (Linux) NILVSim.so, located in the labview/vi.lib/Simulation/Implementation/Shared/ directory, to determine which version of the External Model Interface is installed. Generate C/C++ code that is compatible with the installed version of the External Model Interface.
- Include the SIM_EMI_API.h header file, located in the labview\CCodeGen\Simulation directory. This header file includes definitions and declarations for all functions and data types that the EMI supports.
- Export the EMI_CB_ModelInterface function. You must export the EMI_CB_ModelInterface function for each model you create.
- Export Callbacks functions as appropriate for the structure of the model. For example, if the model contains indirect outputs, you must export the EMI_CB_CalculateIndirectOutputs function to calculate the indirect outputs. If you do not export the appropriate Callbacks functions, LabVIEW returns an error when you attempt to simulate the model.
- Ensure the model has no more than 25 total inputs, outputs, and parameters.
- Build the C/C++ project into a (Windows) .dll, (macOS) .framework or .dylib, or (Linux) .so shared library file.
- Distribute the shared library to end users.
LabVIEW users can use EMI to simulate the external model in the LabVIEW Control Design and Simulation Module.