MATLAB Answers

How can i interrupt a BytesAvailableFcn Callback with an Timer

4 views (last 30 days)
Roland on 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!
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)
%last line following
Slave_gui('Test_Callback', hObject, eventdata, handles);
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
The test_timer.m looks like followed:
function test_timer
global ok;
ok = 1;
t = timer('TimerFcn',@timer_callback, 'ExecutionMode', 'singleShot',... 'StartDelay', 2.0);
while ok
%do something
function timer_callback
ok = 0;
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 Comment

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

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by