How do I add Speedgoat target event listeners and callbacks to an SLRT App?

2 visualizzazioni (ultimi 30 giorni)
I would like to trigger actions in my App Designer app based on Speedgoat target events, for example, when the target is connected, or the real-time application is loaded, started, stopped, etc.
How do I accomplish this for my Simulink Real-Time (SLRT) App?

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 30 Gen 2024
The target object has many events the user can listen for, such as when the real-time target is connected, loaded, started, or stopped. 
To list the available target object events, use the events(tg) function:
>> tg = slrealtime;
>> events(tg)
See the following documentation for a basic code example that can be used in a MATLAB script:
The attached "TargetListenerApp.mlapp" (created with R2023a) shows an example of how to listen for 'started' and 'stopped' target events & to add callback code to an SLRT app:
  • Define listeners as private properties and the related callback functions as private methods:
properties (Access = private)
tg slrealtime.Target
listenerStarted event.listener
listenerStopped event.listener
function StartedFcn(app, event)
  % add callback code for 'started' event
disp('Simulation started callback')
function StoppingFcn(app, event)
% add callback code for 'stopped' event
disp('Simulation stopped callback')
  • Add listeners to the target object in the startupFnc():
function startupFcn(app)
% <....> = slrealtime;
app.listenerStarted = addlistener(,'Started',@(~,~)app.StartedFcn);
app.listenerStopped = addlistener(,'Stopped',@(~,~)app.StoppingFcn);
  • Delete listeners in the UIFigureCloseRequest():
function UIFigureCloseRequest(app, event)
Note that these listeners are attached to whatever the default target is at the time the app is started. Changing the selected target in the Target Selector will have no effect on the listeners. To attach the listeners to a specific target, use = slrealtime('TargetPCName').

Più risposte (0)


Scopri di più su Events in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by