Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
GUI, how to run a fast callback while another long callback is running

Subject: GUI, how to run a fast callback while another long callback is running

From: Daniele Favot

Date: 17 Jul, 2013 20:21:18

Message: 1 of 3

Hi everyone,

the problem that I cannot solve is, in a GUI, to work with pushbutton 1 while another pushbutton callback is running.

With pushbutton 1 I want to display an image in an axes.

Callback of push button 2 is a for cycle in a while cycle.

tic
while toc<50
   for i=1:4
      fprintf(.........)
      fscanf(.........)
      fprintf(.....)
      ...
      ....
   end
end


In the for cycle there is a sequence of commands send through a serial port to an instrument. Some of these commands need some seconds to be completed and one for cycle needs more or less 10 seconds.

Now when I click on Pushbutton 1, the image is displayed only when a for cycle is completed (one i is completed, not all 4 i).

Is there a way to show this image "immediately"?

Every suggestion is appreciated! Thanks

Subject: GUI, how to run a fast callback while another long callback is running

From: matt dash

Date: 17 Jul, 2013 20:39:18

Message: 2 of 3

"Daniele Favot " <danifavi@hotmail.it> wrote in message <ks6ubu$1c4$1@newscl01ah.mathworks.com>...
> Hi everyone,
>
> the problem that I cannot solve is, in a GUI, to work with pushbutton 1 while another pushbutton callback is running.
>
> With pushbutton 1 I want to display an image in an axes.
>
> Callback of push button 2 is a for cycle in a while cycle.
>
> tic
> while toc<50
> for i=1:4
> fprintf(.........)
> fscanf(.........)
> fprintf(.....)
> ...
> ....
> end
> end
>
>
> In the for cycle there is a sequence of commands send through a serial port to an instrument. Some of these commands need some seconds to be completed and one for cycle needs more or less 10 seconds.
>
> Now when I click on Pushbutton 1, the image is displayed only when a for cycle is completed (one i is completed, not all 4 i).
>
> Is there a way to show this image "immediately"?
>
> Every suggestion is appreciated! Thanks

The short answer is no. You have to wait for Pushbutton 2 to finish before using Pushbutton 1.

Subject: GUI, how to run a fast callback while another long callback is running

From: Daniele Favot

Date: 23 Jul, 2013 08:26:12

Message: 3 of 3

> The short answer is no. You have to wait for Pushbutton 2 to finish before using Pushbutton > 1.


I've done it.

I've set a timeout for the serial command of 0.01 second, really small, and after that I've defined a function, to send the commands to the instrument, like this:

function [out]=send2ts(title,port,command);
fprintf (port, ['%R1Q,' command]);
out = fscanf (port);
value=isempty(out);
while value==1;
    if isempty(getappdata(0,'Visitor_GUI'))==0 % check if the Visitor_GUI is launched
        pause(0.2); % let the time to execute the reset alarm button and
                                                      % show the image
    end
    out = fscanf (port);
    value=isempty(out);
end

the trick is in the pause(0.2)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us