Main Content

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.

  1. Create a Simulink® model ext_demo1.slx that has a top-level subsystem with two child subsystems, S1, S2, a MATLAB® Function block, and a Stateflow® chart.

    The S1 and S2 blocks are identical and contain a simple feedback loop.The Stateflow chart contains a simple state machine.

  2. 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);

  3. 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.

  4. In the model, select the top subsystem block. On the PLC Code tab, click Generate PLC Code.

    You generate the ext_demo.L5X code for the top subsystem block, the children S1, S2, the MATLAB function, and Stateflow chart blocks. Also generated is the plc_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.

Related Topics