How can i interrupt a BytesAvailableFcn Callback with an Timer

1 回表示 (過去 30 日間)
Roland
Roland 2013 年 1 月 9 日
コメント済み: Isirame Omofuma 2021 年 2 月 25 日
First of all! Hello Community! This is my first post in this community! That means, most of my problems i had before (and i had a lot of them) were solved without asking a question. But now it is time!
Introduction:
I have two computers (named: 'Master' and 'Slave') running Matlab! On both i have a gui made with guide! The two computers communicate with TCP/IP via Matlab using asynchronous read/write operations. Therefor i use the 'BytesAvailableFcn' to start a communication.
For example: On the Master PC i Press a Button in the gui. In the Button-Callback i send data with TCP/IP. On the Slave PC the 'BytesAvailableFcn' - called 'Bytes_Callback' is called.
In the 'BytesAvailableFcn' i call a function from the Slave-Gui (called 'Test_Callback' (note: for testing, this function i can call also from a button)
function Bytes_Callback(obj, event)
%code
%last line following
Slave_gui('Test_Callback', hObject, eventdata, handles);
end
In these Test_Callback, i call anoter function in an external *.m file. The file called 'test_timer.m' and the function is called 'test_timer'
function Test_Callback (hObject, eventdata, handles);
% code
test_timer;
The test_timer.m looks like followed:
function test_timer
%code
global ok;
ok = 1;
t = timer('TimerFcn',@timer_callback, 'ExecutionMode', 'singleShot',... 'StartDelay', 2.0);
start(t);
while ok
%do something
drawnow;
end
function timer_callback
%code
ok = 0;
Problem
When i am in the while loop, the 'timer_callback' isn't called. But when i start 'Test_Callback' from Slave_Gui without TCP, it works fine!
I also noticed, when i start the routin with Master via TCP, enter while-loop with debugger and wait the 'StartDelay' time, nothing happens, but when i hit 'Exit Debugging Mode' -Button after a while, I then suddenly jump in de 'timer_callback' (i think that means, the timer_callback is in the event_queue).
So my Question, how can i interrupt my routin with an Timer? (Need this, because the 'test_timer' - Routine does exist already!
Maybe another way of solving: Can i instruct Matlab to finish the 'Bytes_Callback' fist, and afterword i call Slave_gui('Test_Callback', hObject, eventdata, handles);
Thanks a lot
Rittmeister - Matlab R2011a
  2 件のコメント
Roland
Roland 2013 年 1 月 14 日
nobody there who has the same problem??
i really need some help or a workaround..
thx Ritmeister - Matlab R2011a
Isirame Omofuma
Isirame Omofuma 2021 年 2 月 25 日
Hi Roland, it's been a couple years since you had this problem. Did you find a work around. I have a very similar problem and been scouring the web for a solution and can't seem to find one. Thanks.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by