How can I programmatically set the enum name of a chart with output port monitoring of child activity?

2 visualizaciones (últimos 30 días)
When editing a Stateflow chart in the model explorer, there is a number of properties that can be set, such as 'Enable zero-crossing detection' etc. The corresponding object of a Stateflow.Chart (obtained using 'sfgco' or 'find') allows setting all these properties programmatically, except for one: the "Enum name"-property for charts where "Create output port for monitoring" is set to "Child activity". Where can I change that property programmatically?
Note that the "OutputData"-property allows setting the properties of the related output data element, but not the "Enum name"-property of the chart. The following screenshot illustrates the issue. After changing the OutputData.DataType-property, the related output data DataType-property changes, but not the "Enum name"-property of the governing chart.

Respuestas (1)

Sebastian Castro
Sebastian Castro el 14 de Jul. de 2015
Editada: Sebastian Castro el 14 de Jul. de 2015
I think you can use the Stateflow API to do this, though it'll take a little bit of digging. For example:
rt = sfroot;
m = rt.find('-isa','Simulink.BlockDiagram');
ch = m.find('-isa','Stateflow.Chart');
After those weird steps, you can search for the state you're interested in.
mode = ch.find('-isa','Stateflow.State','-and','Name','Mode Definitions and Transition');
Once you have "mode", you can look at the table in this document for all the accessible properties and methods of these so-called "Stateflow.State".
Without having access to MATLAB right now, and looking at the properties in that table, I'd guess you do something like:
mode.LoggingInfo.UserSpecifiedLogName = 'modeName';
... but the easiest thing to do is to check by displaying this "mode" variable and seeing which property name is the one with the Enum name.
Good luck, and I hope I'm on the right track :)
- Sebastian
  2 comentarios
Alexander Wille
Alexander Wille el 14 de Jul. de 2015
Editada: Alexander Wille el 14 de Jul. de 2015
Hello Sebastian,
the output data's logging info is not where the enum name is stored. I've done the following: While having a Stateflow chart open in Simulink, I used the following commands:
chart = sfgco;
od = sfgco.OutputData;
li = od.LoggingInfo;
struct(li)
ans =
DataLogging: 0
NameMode: 'SignalName'
LoggingName: 'mode'
DecimateData: 0
Decimation: 1
LimitDataPoints: 0
MaxPoints: 5000
The logging info seems only to be concerned with logging, not with naming the data type of the signal.
Employing find with the '-regexp' and '-property'-flags also does not find any property containing 'Enum' or 'enum':
find(sfroot, '-regexp', '-property', 'Enum')
ans =
handle: 0-by-1
find(sfroot, '-regexp', '-property', 'enum')
ans =
handle: 0-by-1
Your idea of browsing the object hierarchy in search of textual properties containing the data type name, I've come up with the following script:
function searchObjectHierarchyForPropertyValue(startObj, searchString, searchDepth)
machineChecked = false;
if ~searchForPropValue(startObj, 0)
disp(['No property or child object property contained the search string ''' searchString '''.']);
end
function found = searchForPropValue(curObj, curLevel)
found = false;
fn = fieldnames(curObj)';
if isa(curObj, 'Stateflow.Machine')
machineChecked = true;
end
% Iterate over all properties of this object.
for curField = fn
curField = curField{1};
% Retrieve the value of the current property.
curVal = get(curObj, curField);
if isa(curVal, 'handle')
% If the value is a handle and we're not at the maximum
% search depth, drill deeper. Avoid checking a Stateflow
% machine more than once.
if curLevel < searchDepth && ~(isa(curVal, 'Stateflow.Machine') && machineChecked)
if searchForPropValue(curVal, curLevel + 1)
disp(curField)
found = true;
return;
end
end
elseif ischar(curVal)
% A char property was found. Does it contain the search string?
if ~isempty(regexp(curVal, searchString, 'once'))
% If yes, print the property name.
disp(curField)
found = true;
return;
end
end
end
end
end
I know, it will certainly not win a performance or coding medal, but it does the job. The call 'searchObjectHierarchyForPropertyValue(sfgco, 'ignalNam', 5)' proves that no child object of the currently open chart or the chart itself down 'searchDepth' levels has a property whose value is a row vector of chars containing 'modeName'. In case you would like to increase confidence in the algorithm, try changing the search string to a string you know is contained in some property or child object property, e.g. 'ignalNam'.
With this, we can at least eliminate the Stateflow object hierarchy below Stateflow.Charts as a storage place for the enum name property. Stateflow Gurus to the rescue!
Alessio Canepa
Alessio Canepa el 31 de Dic. de 2016
Hi Alexander, I've the same problem. Did you find a way to set that property progmatically? Thanks

Iniciar sesión para comentar.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by