What are the available button callbacks for SLRT UI components?

I am using App Designer to create an app for controlling a real-time application running on Speedgoat hardware. For this, I use Simulink Real-Time (SLRT) specific buttons in my app, such as StartStopButton, ConnectButton, LoadButton, ImportFileLogButton, LatchButton, MomentaryButton, RecordButton, RebootButton, or UpdateButton.
I want to use these buttons to trigger changes within the app. For example, when the user presses the "Connect" button, I want to change a text label in the app. Is this possible?

 Accepted Answer

Since R2024a, dedicated callbacks are available for several SLRT UI components to provide support for pre- and post-events. The components and their event-related properties include:
  • ConnectButton: PreConnectFcn, PostConnectFcn, PreDisconnectFcn, PostDisconnectFcn
  • ImportFileLogButton: PreImportFcn, PostImportFcn
  • LoadButton: PreLoadFcn, PostLoadFcn
  • StartStopButton: PreStartFcn, PostStartFcn, PreStopFcn, PostStopFcn
See the R2024a release notes for details.
In R2023b or earlier, or for SLRT buttons without callbacks, the target object has many events the user can listen for, such as when a parameter is changed, or the real-time target is connected, loaded, started, or stopped. So, one workaround is to add callbacks to these events, which will update the app. See the following MATLAB Answer for details:
Although we always recommend using SLRT App Generator and the dedicated SLRT UI components, you could also re-implement the SLRT UI buttons using regular App Designer components (e.g. uibutton) and connect their callbacks to programmatically interact with Simulink Real-Time. For example, to re-implement a ConnectButton, the "ButtonPushedFcn" callback for a button would call Simulink Real-Time's "tg.connect" function. The error handling for this setup may add some intricacy, but this workflow will allow you to achieve the desired functionality. For a list of the Simulink Real-Time target functions, please refer to the slrealtime.target - Object Functions documentation.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!