How do I force Simulink app setting during startup to impact the target instead of just the GUI?
Simple simulink model converted to app via App Generator & App Designer.
Trying to load last values (from a .mat file) for a given item via callback on Start Button (app.StartStopButton), PreStartFcn.
I check if the file is available, load, then set app value (code below). This results in the GUI correctly displaying the value, however, the underlying component/value (referred to hereafter as the "model value") that the GUI is connected to doesn’t reflect the state of the GUI and is set to the underlying constant value defined in the model. Confirmed model value not loaded during startup via saving state of model value to file via File Log blocks and observing state via SDI. Can also verify value via calculation value is used for that is displayed on the GUI.
The GUI is definitely connected to the model value as when the GUI is updated by the user (after the Start button is pressed), the model value syncs to the GUI state… it is just this initial load that will only update the GUI.
function StartStopButtonPreStart(app, event) % Callback called on Start (pre or post, doesn’t matter).
if isfile(‘DST.mat’)
loadedData = load(‘DST.mat’);
app.DST_Enabled_Value.Value = loadedData.value; % This updates the GUI, but not underlying model value.
end
end
% generic code created by default when utilizing app generator & app
% designer
function startupFcn(app)
% … other setup …
hInst = slrealtime.Instrument();
DST_Enabled_Value_values = [0 1];
DST_Enabled_Value_labels = [0 1];
targetSelector = app.TargetSelector;
slrtcomp = slrealtime.ui.tool.ParameterTuner(app.UIFigure, ‘TargetSource’, targetSelector);
slrtcomp.Component = app.DST_Enabled_Value;
slrtcomp.BlockPath = ‘DST_TimeZone_Test/Subsystem Reference/DST_Enabled’;
slrtcomp.ParameterName = ‘Value’;
slrtcomp.ConvertToComponent = @(val)app.convertValueToValue(val, DST_Enabled_Value_values, DST_Enabled_Value_labels);
slrtcomp.ConvertToTarget = @(val)app.convertValueToValue(val, DST_Enabled_Value_labels, DST_Enabled_Value_values);
slrtInstrumentsComponent = slrealtime.ui.tool.InstrumentManager(app.UIFigure, ‘TargetSource’, targetSelector);
slrtInstrumentsComponent.Instruments = hInst;
% … other setup …
endSimple simulink model converted to app via App Generator & App Designer.
Trying to load last values (from a .mat file) for a given item via callback on Start Button (app.StartStopButton), PreStartFcn.
I check if the file is available, load, then set app value (code below). This results in the GUI correctly displaying the value, however, the underlying component/value (referred to hereafter as the "model value") that the GUI is connected to doesn’t reflect the state of the GUI and is set to the underlying constant value defined in the model. Confirmed model value not loaded during startup via saving state of model value to file via File Log blocks and observing state via SDI. Can also verify value via calculation value is used for that is displayed on the GUI.
The GUI is definitely connected to the model value as when the GUI is updated by the user (after the Start button is pressed), the model value syncs to the GUI state… it is just this initial load that will only update the GUI.
function StartStopButtonPreStart(app, event) % Callback called on Start (pre or post, doesn’t matter).
if isfile(‘DST.mat’)
loadedData = load(‘DST.mat’);
app.DST_Enabled_Value.Value = loadedData.value; % This updates the GUI, but not underlying model value.
end
end
% generic code created by default when utilizing app generator & app
% designer
function startupFcn(app)
% … other setup …
hInst = slrealtime.Instrument();
DST_Enabled_Value_values = [0 1];
DST_Enabled_Value_labels = [0 1];
targetSelector = app.TargetSelector;
slrtcomp = slrealtime.ui.tool.ParameterTuner(app.UIFigure, ‘TargetSource’, targetSelector);
slrtcomp.Component = app.DST_Enabled_Value;
slrtcomp.BlockPath = ‘DST_TimeZone_Test/Subsystem Reference/DST_Enabled’;
slrtcomp.ParameterName = ‘Value’;
slrtcomp.ConvertToComponent = @(val)app.convertValueToValue(val, DST_Enabled_Value_values, DST_Enabled_Value_labels);
slrtcomp.ConvertToTarget = @(val)app.convertValueToValue(val, DST_Enabled_Value_labels, DST_Enabled_Value_values);
slrtInstrumentsComponent = slrealtime.ui.tool.InstrumentManager(app.UIFigure, ‘TargetSource’, targetSelector);
slrtInstrumentsComponent.Instruments = hInst;
% … other setup …
end Simple simulink model converted to app via App Generator & App Designer.
Trying to load last values (from a .mat file) for a given item via callback on Start Button (app.StartStopButton), PreStartFcn.
I check if the file is available, load, then set app value (code below). This results in the GUI correctly displaying the value, however, the underlying component/value (referred to hereafter as the "model value") that the GUI is connected to doesn’t reflect the state of the GUI and is set to the underlying constant value defined in the model. Confirmed model value not loaded during startup via saving state of model value to file via File Log blocks and observing state via SDI. Can also verify value via calculation value is used for that is displayed on the GUI.
The GUI is definitely connected to the model value as when the GUI is updated by the user (after the Start button is pressed), the model value syncs to the GUI state… it is just this initial load that will only update the GUI.
function StartStopButtonPreStart(app, event) % Callback called on Start (pre or post, doesn’t matter).
if isfile(‘DST.mat’)
loadedData = load(‘DST.mat’);
app.DST_Enabled_Value.Value = loadedData.value; % This updates the GUI, but not underlying model value.
end
end
% generic code created by default when utilizing app generator & app
% designer
function startupFcn(app)
% … other setup …
hInst = slrealtime.Instrument();
DST_Enabled_Value_values = [0 1];
DST_Enabled_Value_labels = [0 1];
targetSelector = app.TargetSelector;
slrtcomp = slrealtime.ui.tool.ParameterTuner(app.UIFigure, ‘TargetSource’, targetSelector);
slrtcomp.Component = app.DST_Enabled_Value;
slrtcomp.BlockPath = ‘DST_TimeZone_Test/Subsystem Reference/DST_Enabled’;
slrtcomp.ParameterName = ‘Value’;
slrtcomp.ConvertToComponent = @(val)app.convertValueToValue(val, DST_Enabled_Value_values, DST_Enabled_Value_labels);
slrtcomp.ConvertToTarget = @(val)app.convertValueToValue(val, DST_Enabled_Value_labels, DST_Enabled_Value_values);
slrtInstrumentsComponent = slrealtime.ui.tool.InstrumentManager(app.UIFigure, ‘TargetSource’, targetSelector);
slrtInstrumentsComponent.Instruments = hInst;
% … other setup …
end simulink, startup loading, gui but not target MATLAB Answers — New Questions









