How do I pass an object into a timer callback function?

10 ビュー (過去 30 日間)
PW
PW 2018 年 3 月 30 日
コメント済み: Jon 2022 年 4 月 27 日
The main part of my code has an object called cam. In the middle of the code, I want to call a timer to execute [~,b]=cam.Aqquisition.IsFished every second and output b.
cam = uc480.Camera;
%... unrelated
t = CheckTimer;
start(t)
In a separate file, I have
function t=CheckTimer
t = timer;
t.TimerFcn = @check;
t.Period = 1;
t.TasksToExecute = 10;
t.ExecutionMode = 'fixedSpacing';
end
function check(~,~)
[~,b]=cam.Acquisition.IsFinished
end
The error message is: Undefined variable "cam" or class "cam.Acquisition.IsFinished". if I put cam.Acquisition.IsFinished in main part of my code, it works fine.
cam = uc480.Camera;
%... unrelated
[~,b]=cam.Acquisition.IsFinished
How do I pass the object "cam" into a timer callback function and output "b"?
  1 件のコメント
Jon
Jon 2022 年 4 月 27 日
I have a similar problem, did you ever find a solution?

サインインしてコメントする。

採用された回答

Sean de Wolski
Sean de Wolski 2022 年 4 月 27 日
Pass cam in with an anonymous function when you create the timer
cam = camera
t = timer(TimerFcn=@(~,~)checkFinished(cam))
function checkFinished(cam)
whatever_with(cam)
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by