Generate Structured Text Code with Logging Instrumentation

This topic assumes that you have generated Structured Text code from a Simulink® model. If you have not yet done so, see Generate Structured Text from the Model Window.

The example in this topic shows generated code for the Rockwell Automation® Studio 5000 IDE. Generated code for other IDE platforms looks different.

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

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

  3. The MATLAB function block implements the following 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);

  4. Select the top-level subsystem and open the configuration parameters window. On the PLC Code Generation pane, select the Target IDE as Rockwell Studio 5000: AOI. On the Identifiers pane, select Generate logging code.

  5. In the model, select the top subsystem block, right-click, and choose PLC Code>Generate Code for Subsystem.

    This operation generates L5X AOI code for the top subsystem block and the children S1, S2, MATLAB function, and Stateflow chart blocks. In the code folder, it also generates plc_log_data.mat which has the logging data information.

  6. After generating the code, you can download and run the logging code from the PLC IDE.

Related Topics