Adding up the block statistics for two adjacent blocks in Simevents

3 views (last 30 days)
I've spent two days tearing my hair out trying to understand upgraded Simevents (Legacy Simevents much easier!). Frustration aside....
I have two adjacent Entity Servers, one feeding the next. (One is a one item painting rack for widgets, followed by an 8 item shelf drying rack for the painted widgets).
I would like to create a scope with a counter showing the number of widegts in both servers i.e. a sum. I have created "Number of entities in Block, n" data ports for the blocks in Statistics but can't for the life of me add the two numbers together and output to:
  1. A scope or
  2. A function (I'd like to do some switching up and down stream based on how many are here)
I know this will be ridiculously easy but .....
Thanks for the help.

Accepted Answer

Paul on 6 Sep 2020
Edited: Paul on 6 Sep 2020
I definitely owe you a beer. This is a massive, help in particular the attached example.
In this example the Server calls the function and returns the result to the attribute (attribute1 in this example).
If I wanted to create a function that operates independent of a single entity how might I do that?
A specific example might be sending a control signal to an output or output switch that depends on the amouint of WIP in the servers ? I'd like to call a function from the switch but that doesn't seem to be an option - requiring instead a control signal. Maybe introduce a [logic] buffer upstream and call from that?
Below I've modified your function to allow for a max number in the painting cycle (seal_cycle_max), checked to see if it's grerater that max and want to create a control signal that switches products upstream. However I'm unclear how to get the control_signal from the Matlab block to the Input Switch. There seem to be to "out" blocks both in the image and am unsure if I use one of these (what's the difference?)or something else.
function seal_control_signal = MyFunction (WIP_Server1, WIP_Server2, seal_cycle_max)
WIP = WIP_Server1 + WIP_Server2;
if mystatistic >= seal_cycle_max
Many thanks. Once I get going I won't be such a nuisance!
Paul on 7 Sep 2020
ok, that makes sense. This also highlights the new version of Simevents seems to lean more on Simulink than before. I had largely been ignoring Simulink functions. Thanks very much for clarifying.

Sign in to comment.

More Answers (1)

Abdolkarim Mohammadi
Abdolkarim Mohammadi on 4 Sep 2020
Edited: Abdolkarim Mohammadi on 4 Sep 2020
If I have understood you correctly, you want to calculate the system's WIP (Work In Progress). You can use the Add block to sum up the number of entities in each of the blocks. For example:
The scope shows:
Abdolkarim Mohammadi
Abdolkarim Mohammadi on 5 Sep 2020
Edited: Abdolkarim Mohammadi on 5 Sep 2020
Many thanks, Paul.
1) They just differ visually. I prefer rectangular because it is visually consistent with other blocks.
2) You want the function to be callable from event actions, so you should use Simulink Function. And you want to write textual MATLAB functions within it, so it should contain MATLAB function block. I have attached an example, where the Entry event action of the second server calls GetWIP() function.

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!