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

1 回表示 (過去 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

カテゴリ

Help Center および File ExchangeTarget Computer Setup についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by