Lamp VS Guage - App Designer

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.

12 Comments

I do not know what you mean by instrumentate a scalar or what is connectScalar. You can change color or state (enable or disable). You can set some threshold, when the signal is above it, set the state to enable and vice versa.
Thank you Mario, for your reply.
I know that you can tune the parameters of the lamp, as you said. What I was trying to do, is baically change / display parameters from a Simulink real time application on the app. I am using an Instrumentation display.
These links have some information about the Instrumentation:
You can find an applied example on this link:
I am having problems linking the signal to the Lamp...
Probably requires an output argument.
hScalar = connectScalar(instrument_object,hDisplay,blockPath,portIndex)
% hScalar = connectScalar(instrument_object,hDisplay,blockPath,portIndex,Name,Value)
Tried that on the degubber, the same error still. The suggested construction seems to be used outside of the app designer. For the apps, the initial construction seems to be preffered, like on the applied example.
The only difference I could find was the hDisplay parameter: for the guage it would work, but not for the lamp...
What about this line? Maybe it is required as it has the "[app.mdl '/TankLevel']"
[~,line2] = app.hInst.connectLine(app.UIAxes,[app.mdl '/TankLevel'] ,1,'MaximumNumPoints',10000)
I have no clue about simulink and instrumentation in App Designer though, just giving some suggestions.
Thank you for the suggestion, I wil try it.
The solution I found was to connect the Simulink real time to an invisible Guage on the app. And then with a callback on the instrumentation object, updating the color of the Lamp acording to the value of the Guage. I am sorry there should be a better way to do this, yet I could not found one...
Hi Jose,
Unfortunately in the prototype version of the Instrumentation object, there isn't a way to connect a signal in model to a lamp directly using connectscalar and I believe you figured out that it was because the lamp expects an RGB color. This is actually resolved in R2020b as the instrument object has support for using arrayindex (for wide signals) or custom callbacks that are called before data is sent to the graphical component.
For R2020a and R2019b (where the prototype instrument was introduced), you can use connectCallback method to connect a signal to a specific callback in your app. In that callback, you could update the lamp based on the signal data. This should be more responsive than the current approach of updating a gauge, reading the gauge, and then updating the lamp.
Jose Santos
Jose Santos on 23 Oct 2020
Edited: Jose Santos on 23 Oct 2020
Hi Jon.
Many thanks for your comment.
The base idea, was to change the color of the Lamp depending on the value of a "state" signal, (e.g. red=0, amber=1, green=2). I don't want to increase the signal size (passing from a double to a wide signal), just to create the RGB color on the simulink. As it is more of an informative nature, I would prefer to have the calculations of the color being done on the app, rather than on the target/ Simulink model.
We have now updated to the v2020b, and the instrumentation object improved significantly. But I still cannot find the references material about the personalised callbacks. My main issue, is that I seem that I cannot acess the value of the streamed signals before streaming them to a editfield or gauge. I think there should be a way to pass the value to the callback, but I cannot find how to do it.
This, then, causes other issues. I tried to plot the difference between two signals (using maybe connectline to axis on the app). Plotting the signals works fine, but to plot the subtraction of one signal to the other is beyond my current capabilities. I reckon I would need a callback somewhere, instead of connectline.
Hi Luke,
With connectLine and connectScalar there is an input argument for providing your own custom callback. You could use this to the red = 0, amber = 1 green = 2 into the RGB values that a lamp requires.
You can find an example of this in the section "Apply Instrument Object Methods" in the doc link below:
When you use the callback field to do this, you can operate on the data before it is passed to the lamp (or other graphics component).
I'll have to think about plotting the difference between two signals. I'll try to put an example together for that.
Thanks for posting this, I was having a hard time finding this information.
It's a bit ridiculous that we have to know to use a hidden function to connect the uilamp object with the instrument data stream. Shouldn't there at least be some default behavior where it is able to connect the scalar data stream to the uilamp and these additional settings are only necessary to deviate from the default - rather than the code just failing.
I completely agree with Timothy's statement. Thanks for the explanation, but it is very illogical.

Sign in to comment.

 Accepted Answer

Jose Santos
Jose Santos on 6 Nov 2020
Edited: Jose Santos on 6 Nov 2020
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.

More Answers (1)

Pablo Romero
Pablo Romero on 24 Oct 2023
Edited: Pablo Romero on 24 Oct 2023
Please check out the documentation page below for a built-in example.

Products

Release

R2020a

Community Treasure Hunt

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

Start Hunting!