Why do the block ports disconnect when I update a model with a Level 2 MATLAB S-Function in it?
2 views (last 30 days)
Show older comments
MathWorks Support Team
on 4 Aug 2020
Answered: MathWorks Support Team
on 26 Jan 2021
I wrote a Level 2 MATLAB S-Function, and whenever I update my model (ctrl + d), the input ports disconnect from the block. See the screenshots below and the attached files. Why does this happen? Are there any workarounds?
Before updating the model:
After updating the model:
Accepted Answer
MathWorks Support Team
on 4 Aug 2020
This issue is related to the "NumInputPorts" property of the "Simulink.RunTimeBlock" class:
This occurs when the NumInputPorts is initially set to zero in the "setup" method of the S-Function, and then is later set to a nonzero value:
The ports on the block are dynamically updated, so when the following line is executed,
>> block.NumInputPorts = 0;
All of the input ports from the block are removed. Then, when
>> block.NumInputPorts = 1;
is executed, an input port is added to the block, but there is no memory of previous connections, so the input signal is disconnected.
If you need to write logic in your S-Function to determine the number of ports the block will have, use an intermediate variable as follows:
0 Comments
More Answers (0)
See Also
Categories
Find more on Programmatic Model Editing 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!