How to connect a substruct of an array to an inport of a 'for each' block

2 views (last 30 days)
Hi all, next challenge
From a PLC I receive data in form of a 'struct in struct' principle which I want to use in the simulation model. How to connect the substructs to a 'for each' block in simulink (and how to configure it)?
In details:
The PLC logs the data each PLC scan according to the structure of its program. The data has an array of devices 'arrstDevDspBox(n)' and that contains several substructs (the layout/byte size is known). It is buildup like this:
simSignalDataIn.arrstDevDspBox(1).stHW.stIN.stAdc.C1 = timeseries(int16(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stHW.stIN.stAdc.R1 = timeseries(int16(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stHW.stIN.stAdc.C2 = timeseries(int16(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stHW.stIN.stAdc.R2 = timeseries(int16(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stHW.stIN.stAdc.C3 = timeseries(int16(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stHW.stIN.stAdc.R3 = timeseries(int16(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stHW.stIN.stAdc.C4 = timeseries(int16(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stHW.stIN.stAdc.R4 = timeseries(int16(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stHW.stIN.nStatusFromMotors = timeseries(uint16(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stLYR.stIN.stDevDspProbeA.bCmdMoveUpComplete = timeseries(logical(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stLYR.stIN.stDevDspProbeA.bStaDriveIssue = timeseries(logical(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stLYR.stIN.stDevDspProbeA.bStaOperational = timeseries(logical(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stLYR.stIN.stDevDspProbeB.bCmdMoveUpComplete = timeseries(logical(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stLYR.stIN.stDevDspProbeB.bStaDriveIssue = timeseries(logical(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stLYR.stIN.stDevDspProbeB.bStaOperational = timeseries(logical(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stLYR.stIN.bCmdClearBuffer = timeseries(logical(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stLYR.stIN.bStaHeightMeasurementActive = timeseries(logical(1),simTimeData);
simSignalDataIn.arrstDevDspBox(1).stLYR.stIN.fActXposition = timeseries(double(1),simTimeData);
This data is imported into MATLAB and the structure is available as 'struct in struct' of timeseries. I created a subsystem that is capable of handling this device data which I want to call in a 'for each' loop.
So with the example above I want to connect 'simSignalDataIn.arrstDevDspBox(n).stHW.stIN' to the input 'i_stHW' from the 'for each' block. And the 'simSignalDataIn.arrstDevDspBox(n).stLYR.stIN' to the input 'i_stLYR' from the 'for each' block. In case that it matters, all block inputs have a distinct 'simulink.bus' definition available.
Within a text based (PLC) programm I would make something like:
For idx = 1 to 12
devDspBox( ...
i_stHW := simSignalDataIn.arrstDevDspBox(idx).stHW.stIN, ...
i_stLYR := simSignalDataIn.arrstDevDspBox(idx).stLYR.stIN)
So how to do this in simulink? Thanks for any reply upfront.

Accepted Answer

Ludo Houben
Ludo Houben on 8 Dec 2023
It looks that my preferred way of working is not supported within Simulink. So I now constructed it like this:
It looks like it is working as intended, so fit for my purpose. The code looks clean enough to me.

More Answers (0)


Find more on Simulink PLC Coder in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!