A number of the Target object functions produce event status. How can I use the MATLAB listener function to monitor event states?

2 次查看(过去 30 天)
As stated in Simulink® Real- Time™API Guide,“A number of the Target object functions produce event status. You can use the MATLAB listener function to monitor event states.”
But,How can I use the MATLAB listener function to monitor event states?
For example, I want to get the connect status of target.How do I code?

回答(1 个)

Jon Lobo
Jon Lobo 2022-12-19
编辑:Jon Lobo 2022-12-19
Hi Yuxuan,
I'm including some example code for how to do this.
tg = slrealtime;
listenerConnected = listener(tg,'Connected',@(~,~)disp('Connected to target computer'));
listenerDisconnected = listener(tg,'Disconnected',@(~,~)disp('Disconnected from target computer'));
listenerLoaded = listener(tg,'Loaded',@(~,~)disp('Loaded application on target computer'));
listenerStarted = listener(tg,'Started',@(~,~)disp('Started application on target computer'));
listenerStopped = listener(tg,'Stopped',@(~,~)disp('Stopped application on target computer'));
listenerStopped = listener(tg,'Stopped',@(~,~)disp('Stopped application on target computer'));
This code executes a series of target computer operations with pauses between the operations to provide time to observethe event status messages.
connect(tg);
load(tg,model);
start(tg);
stop(tg);
disconnect(tg);
Connected to target computer
Stopped application on target computer
Loaded application on target computer
Started application on target computer
Stopped application on target computer
Disconnected from target computer
Ultimately, there are a lot of other events you can use. To list the available events, use:
events(tg)
-Jon

Community Treasure Hunt

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

Start Hunting!

Translated by