To integrate a custom function block, ExternallyDefinedBlock, this procedure uses the
example plcdemo_external_symbols
.
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:
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 plcdemo_external_symbols
.
Open the Configuration Parameters dialog box for the model.
Add ExternallyDefinedBlock
to PLC Code Generation > Identifiers > Externally Defined Identifiers.
The plcdemo_external_symbols
model also suppresses
K1
and InBus
. Add these symbol names
to the Externally Defined Identifiers field,
separated by spaces or commas. For other settings, see the
plcdemo_external_symbols
model.
Save and close your new model. For example, save it as
plcdemo_external_symbols_mine
.
Generate code for the model.
In the generated code, look for instances of
ExternallyDefinedBlock
.
The reference of ExternallyDefinedBlock
is:
The omission of ExternallyDefinedBlock
is: