How to display the real-time numerical value of a Simulink signal in a box in an App Designer app?

조회 수: 29 (최근 30일)
I have been trying to display the value of a signal in my GUI. For clarity to people reading this, I have text boxes in an app (made using Simulink's AppDesigner) called measurement1, measurement2, and measurement3. There are also three signals in my Simulink model called signal1, signal2, and signal3, which are always changing in real-time to various values ranging from 0 to 300. The paths for these signals are 'System/UI/signal1', 'System/UI/signal2', and 'System/UI/signal3'.
I want to show the numerical value of signal1 in the GUI, in the measurement1 text box. The same for signal2 in measurement2, and signal3 in measurement3.
To avoid confusion: In the picture, you can see I convert them to strings. This is just so their values appear in the Simulink displays called disp_signal1/2/3. Without converting to a string, their values would not appear in those displays.
GUI/App:
But it wasn't quite enough to help me. I tried following the solution but it wasn't working (the text box still just shows 0). It's possible I was not supposed to type everything as shown, but I am not sure what parts of that code only apply to their model/GUI. I also tried doing this:
app.measurement1.Text = getsignal(tg, 'System/UI/signal1', 1);
But it says:
Error using slrealtime.Target/throwErrorWithCause
Unable to get 'System/UI/signal1:1' signal value on target computer 'TargetPC1: 'System/UI/signal1' block does not exist.
Error in slrealtime.Target/getsignal
Caused by:
Error using slrealtime.internal.SignalAccess/getSignalInfoFromCodeDescriptor
'System/UI/signal1' block does not exist.

채택된 답변

Dimitri MANKOV
Dimitri MANKOV 2025년 2월 6일
Hi Kevin,
Have you tried using a Simulink Real-Time Insturement object instead of the "getsignal" function embedded within a timer object? The instrument object has been introduced in MATLAB R2020b and greatly simplifies the design of UIs for Simulink Real-Time in App Designer.
Futhermore, the Simulink Real-Time App Generator tool introduced in MATLAB R2022a can help you generate a first draft of a UI specific to your application, with the correct instrumentation callbacks written automatically.
I hope this is helpful!
Dimitri
  댓글 수: 1
Kevin
Kevin 2025년 2월 18일
Hi thank you for your prompt response. App Generator solved my issue. I had initially tried using the App Generator but had trouble figuring it out. Coming back to it later I understood it better and also figured out how to use it to add signals to my GUI after-the-fact.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Target Computer Setup에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by