Generate Structured Text Code That Has Logging Instrumentation
This example shows how to generate code for the Rockwell Automation® Studio 5000 IDE by using external mode logging.
Create a Simulink® model
ext_demo1.slxthat has a top-level subsystem with two child subsystems,S1,S2, a MATLAB® Function block, and a Stateflow® chart.
The
S1andS2blocks are identical and contain a simple feedback loop.The Stateflow chart contains a simple state machine.

The MATLAB function block implements this code:
function y = fcn persistent i; if isempty(i) i=0; end if (i>20) i = 0; else i=i+1; end y = sin(pi*i/10);Select the top-level subsystem and open the PLC Coder app. On the PLC Code tab, click Settings > PLC Code Generation and select the Target IDE as
Rockwell Studio 5000: AOI. On the Interface pane, select Generate logging code. Click OK.
In the model, select the top subsystem block. On the PLC Code tab, click Generate PLC Code.
You generate the
ext_demo.L5Xcode for the top subsystem block, the children S1, S2, the MATLAB function, and Stateflow chart blocks. Also generated is theplc_log_data.mat, which has the external logging data information.
To run the ext_demo.L5X file in the Rockwell Automation Studio 5000 IDE, see Visualize and Monitor Logging Data by using Simulation Data Inspector.