This workflow is supported for Rockwell Automation® targets. This workflow shows you how to set up an Open Platform Communications (OPC) server and use the Simulation Data Inspector in Simulink® to visualize and monitor the logging data.
The following procedure shows you how to create a Studio 5000 project to import the generated logging code. You can use a similar procedure to import the generated code into an existing project.
Start the Studio 5000 IDE and create project with the name
ext_demo1
.
Import the generated ext_demo.L5X
to the Add-On
Instructions tree node of the project.
In the MainProgram
node, delete the ladder
MainRoutine
and create an ST
MainRoutine
node.
In ST MainRoutine
, define the following
tags:
Tag Name | Tag Type |
---|---|
i0_Subsystem | Subsystem |
i0_Subsystem_val | Subsystem_log |
Init | BOOL |
Y1 | REAL |
Y2 | REAL |
Y3 | DINT |
The tag definition looks like the following in Studio 5000 IDE,
i0_Subsystem tag
is the instance of the top
subsystem AOI, the i0_Subsystem_val tag
is the log
data with structure type Subsystem_log
. Set the
initial value of init
tag to 1.
Double-click MainRoutine
tree node and type in the
following code. The statement Subsystem(i0_Subsystem, 23, Y1,
Y2, Y3, i0_Subsystem_val)
calls the logging method
(ssmethod value=23)
to log in data to the
i0_Subsystem_val
tag.
Compile the project in Studio 5000 IDE, connect, and download to the PLC target.
Start RSLinx Classic Gateway, select the menu item
DDE/OPC->Topic Configuration
.
In the resulting pop-up dialog box, create a topic
ext_demo1
by using the New
button. Select the target PLC from the PLC list.
Click Yes
button to update the topic
(ext_demo1
).
To verify that the log data is set up on the OPC server, select the
menu item Edit->Copy DDE/OPC Link
. The
i0_Subsystem_val
tag for log data must be shown
on the RSLinx OPC Server.
After the RSLinx OPC Server is configured, you can use the PLC external mode
commands to connect to the server, stream, and display live logging data on the
Simulation Data Inspector. The log data information is in the
plc_log_data.mat
file which can be found in plcsrc
folder. You can use the plcdispextmodedata
function to display the contents of the MAT-file.
In the MATLAB® command,
type:
>>cd plcsrc >>plcdispextmodedata plc_log_data.mat
Log data: #1: Y1: LREAL #2: Y2: LREAL #3: Y3: LREAL #4: io_Chart.out: DINT #5: io_Chart.ChartMode: DINT #6: io_Chart.State_A: BOOL #7: io_Chart.State_B: BOOL #8: io_Chart.State_C: BOOL #9: io_Chart.State_D: BOOL #10: io_Chart.is_active_c3_Subsystem: USINT #11: io_MATLABFunction.y: LREAL #12: io_MATLABFunction.i: LREAL #13: io_S1.y: LREAL #14: io_S1.UnitDelay_DSTATE: LREAL #15: i1_S1.y: LREAL #16: i1_S1.UnitDelay_DSTATE: LREAL
The format for the log data information is index number, name, and type. The log
data for non-top subsystem function block output and state variables are named using
the dot notation to represent the function block instances that own the data. The
index and name of the log data can be used with the plcrunextmode
command to specify a subset of log data for streaming and visualization.
Use the plcrunextmode
function to connect to the OPC server and stream log
data. For example, executing plcrunextmode ('localhost', 'studio5000',
'ext_demo1', 'plc_log_data.mat');
command streams live log data for
the example model in to Simulation Data Inspector.
The plcrunextmode
command continues to run and stream log data.
To exit streaming, type Ctrl-C in MATLAB to stop.
plcdispextmodedata
| plcrunextmode