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

2 次查看(过去 30 天)
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)
Next
So how to do this in simulink? Thanks for any reply upfront.
Ludo

采纳的回答

Ludo Houben
Ludo Houben 2023-12-8
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.
Regards
Ludo

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink PLC Coder 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by