How to read the value of a 'Local' Data field in stateflow using Simulink test?

2 次查看(过去 30 天)
For whitebox testing (using Simulink Test) of a stateflow diagram I need to read some data field values which has its Scope type set to 'Local'. How can this be done?

采纳的回答

Renato SL
Renato SL 2019-9-4
I found something else. There is an old blog post about it (here) that describes the idea.
In the Model Explorer window (where you define data and its Scope type), when you click on a data, on your right hand side you can set certain parameters of the data.
Click on the Logging tab, and tick the Log signal data box.
logging.png
This is a screenshot from my example.
After that, once you run the simulation, click on the Simulation Data Inspector button (beside the Simulation stop time box, top side of the Simulink window) and you can see the logged data there.
logging2.png
In the screenshot above, it's the one in the red circle.
I think it would turn yellowish once you run the simulation and you have a logged data.
I think this is how you can test the model without physically altering the blocks, which is what you are looking for.
  2 个评论
bert de Jong
bert de Jong 2019-9-4
OK nice, almost there.
The only thing still needed is actually reading the logged value(s) at runtime. I tried some stuff, and I can actually read the logged values using:
logsout.getElement('NAME_OF_SIGNAL').Values.Data
However the logsout variable only gets loaded after the simulation is finished.
Renato SL
Renato SL 2019-9-4
From the documentation of the data inspector (here), I believe it isn't meant to be used during runtime. For Matlab in general, I also think that observing data during runtime for the sake of seeing it change through time is not facilitated. (I found an interesting discussion here).
Other than observing the logsout through the command window, I think it's better to see it directly with the Simulation Data Inspector.
While opening the inspector, you could progress the simulation some steps at a time (by clicking the Step Forward button beside the Run button).
If this is what you meant by 'reading the logged value(s) at runtime', then this should be it.

请先登录,再进行评论。

更多回答(1 个)

Renato SL
Renato SL 2019-9-4
I think you should create a new data with Scope type set to 'Output'. This new data will just take the value of the concerned Local data so that it can be inspected from outside of the Chart.
%example
en:
x = 0; %the local data
du:
x = x + 1; %something is done to the local data
y = x; %the output data takes the value of the local data
I explored this possibility some time ago and I made this simple example (.slx file attached). I hope this helps.
  1 个评论
bert de Jong
bert de Jong 2019-9-4
Hi Renato,
Thanks for your answer.
I understand changing the data scope to 'output' will make it easily readable from outside the stateflow block, however this would mean I have to modify my model just for testing. As a consequence, my model which uses the model under test, will be cluttered with a lot of unused terminated outputs.
Also, routing the local signals out, makes the test more black box than white box. I expect/hope simulink test supports white box testing.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Inputs 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by