Add Subsystem Port and Bus Descriptions in Generated Code
This example shows how to add descriptions for subsystem input ports, output ports, and buses. The generated structured text code then includes these port and bus descriptions.
The model consists of two buses:
aBus that has three elements and
bBus that has two elements. The model also consists of a Subsystem block that performs operations on the individual elements of the buses.
Open the model.
Input and Output Port Descriptions
The descriptions for your input and output ports appear in the generated structured text code. The input and output ports must be inside the Subsystem block for their descriptions to appear in the generated code. To add a description to an input or output port block, right-click the block, select Properties, and enter a description in the Description field. This image shows the port description for input port
The descriptions for your buses appear in the generated code. The descriptions for buses appear as
struct data types. To add a description for a bus, open the Type Editor. In the MATLAB Command Window, enter:
In the Type Editor, select the bus object and enter the description in the Description field. This image shows the description for the bus object named
To generate structured text code, do one of the following:
Open the PLC Coder app. Select the
SimpleSubsystemblock and click
Generate PLC Code.
### Generating PLC code for 'GenerateComments/Subsystem'. ### Using model settings from 'GenerateComments' for PLC code generation parameters. ### Gathering test vectors for PLC testbench. ### Begin code generation for IDE codesys23. ### Emit PLC code to file. ### PLC code generation successful for 'GenerateComments/Subsystem'. ### Generated files: plcsrc/GenerateComments.exp
Descriptions in Generated Code
The descriptions for the subsystem ports and buses appear in the generated code.
This image shows the input port descriptions in the generated code.
This image shows the bus descriptions in the generated code.
Close the Model