MATLAB: Lamp VS Guage – App Designer

app designerMATLABreal timesimulinkSimulink Real-Timespeedgoat

Hi,
I am trying to build an app to instrumentate my Simulink Real time application. The version is 2020a.
On the startup function I call the instrumentation starter, which goes like this.
function setupInstrumentation(app)
app.hInst = SimulinkRealTime.prototype.Instrumentation(app.mdl);
app.hInst.connectScalar(app.ReadyLamp,[app.mdl '/Initialization_Check'],14); % Link a boolean signal to a lamp on the app
app.StartStopButton.Icon = app.startIcon;
app.StartStopButton.Text = 'Start';
end
The ConnectScalar line then produces the following error:
Error using SimulinkRealTime.prototype.Scalar
Unknown property name for hScalar
Error in SimulinkRealTime.prototype.Instrumentation/connectScalar
I tried to find the parameter and aparently it is the output of the script. So I tried with a Guage instead of a Lamp, and this code works fine.
app.hInst.connectScalar(app.Gauge,[app.mdl '/Initialization_Check'],14); % Link the same signal to a Guage
So, we can instrumentate a Scalar to a Guage, but not to a lamp? Is there a work around to link the signal to the lamp?
Thank you in advance.
EDIT:
I think I got an update about how this does not work.
The Gauge display has a entry for the value to display, while the Lamp only has a parameter for the color of the lamp. What I think it is required is a way to change the color of the lamp depending on the value of the signal. this link seems to have a connection between the Simulink signal and the Visible parameter of the lamps, but I don't understand what it is happening and no example is shown, just code. Is it also possible to link the signal to the color parameter of the lamp?
This code can change the visibility parameter of the lamp, (signal==1 -> 'On', signal~=1-> 'Off')
app.hInst.connectScalar(app.Lamp,'Signal_location',1, 'PropertyName', 'Visible', 'Callback', @(t,d)string(slprivate('onoff',d==1)));
Looking for an answer to change the color.

Best Answer

Finally, with the help of the Speedgoat Support, I can change the color of the lamp depending on the signal (for V2020b) directly, without the need for a Guage as intermidiate step.
My solution lines:
app.hInst = slrealtime.Instrument(app.mdl);
app.hInst.connectScalar(app.OnTargetLamp,[app.mdl '/RIG_Control'],1, 'PropertyName', 'Color', 'Callback', @app.Lampper);
function color=Lampper (~,~,d)
if d
color=[0,1,0]; % If value == 1, color is green.
else
color=[1,0,0]; % If value == 0 or not defined, color is red.
end
end
As I store the Instrumentation object on the App variables, the syntax can be slightly different than normal, but I also but the generic syntax below for future reference:
app.hInst = slrealtime.Instrument('Simulink Model');
app.hInst.connectScalar('-GUI Lamp','-Block Path','-IO number', 'PropertyName', 'Color', 'Callback', @'app.-fcnName');
function '-dummy out variable'= '-fcnName'(app,time,signal)
'algorithm to deal with the signal'
end
If you want to change more than one item, but all with the same effect. You can scale the connectScalar line to the different App Items.
If you want to have different behaviours for the same signal. Maybe use the addSignal + connectCallBack method.