Integrate Custom Function Block in Generated Code
To integrate a custom function block, ExternallyDefinedBlock, this procedure uses the
plcdemo_external_symbols. To open the example,
In a Simulink® model, add a MATLAB Function block.
Double-click the MATLAB Function block.
In the MATLAB® editor, minimally define inputs, outputs, and stubs. For example:
Functions that have only one output, no states, and do not access global variables are generated as
FUNCTIONin the generated structured text code.
function Y = fcn(U,V) % Stub behavior for simulation. This block % is replaced during code generation Y = U + V;
Change the MATLAB Function block name to ExternallyDefinedBlock.
Create a subsystem from this MATLAB Function block.
Complete the model to look like the Subsystem block in.
Open the Configuration Parameters dialog box for the model.
ExternallyDefinedBlockto PLC Code Generation > Identifiers > Externally Defined Identifiers.
plcdemo_external_symbolsmodel also suppresses
InBus. Add these symbol names to the Externally Defined Identifiers field, separated by spaces or commas. For other settings, see the
Save and close your new model. For example, save it as
Generate code for the model.
In the generated code, look for instances of
The reference of
The omission of