A number of the Target object functions produce event status. How can I use the MATLAB listener function to monitor event states?
2 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Jon Lobo
on 19 Dec 2022
Edited: Jon Lobo
on 19 Dec 2022
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
0 Comments
See Also
Categories
Find more on Target Computer Setup in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!