MATLAB Answers

0

How can i interrupt a BytesAvailableFcn Callback with an Timer

Roland 님이 질문을 제출함. 9 Jan 2013
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

  댓글 수: 1

nobody there who has the same problem??
i really need some help or a workaround..
thx Ritmeister - Matlab R2011a

로그인 to comment.

답변 수: 0


Translated by