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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/705177/image.png)
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Target Computer Setup에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!