[Scilab-users] user terminate program (exit while loop)

aweeks at hidglobal.com aweeks at hidglobal.com
Fri Jun 27 15:45:22 CEST 2014


Hi Pascal,

I've wanted to do this too.
You might like to look at link
http://compgroups.net/comp.soft-sys.math.scilab/non-blocking-keyboard-input/2083213
which is very similar to Samuel Gougeon's suggestion.

Samuel says his proposal is untested but I use this method and it works for
me.  I've pasted the basis of my code below and apologise if it doesn't
work in your setup because I position the windows and text boxes to suit
the layout on my monitor.  If you have a question feel free to ask.


global figrhdl;
global stophdl;
global stoploop;

function StopLoop(win, x, y, ibut)
    global stoploop;
    if ibut == -1000 then stoploop = %t; end
    if ibut == 3 then
        stoploop = %t;
        mprintf("Loop stopped.\n");
    end
endfunction

function StartDisplay()
    global figrhdl;
    global stophdl;
    figrhdl = scf(1);
    xstring(-0.1,1.1,"LEFT CLICK HERE TO STOP LOOPING");
    stophdl = gce();
    stophdl.font_style = 0;
    stophdl.font_size = 2;
    stophdl.box = 'on';

    seteventhandler('StopLoop');
    figrhdl.event_handler = 'StopLoop';
    figrhdl.event_handler_enable = 'on';
endfunction

stoploop = %f;		// The endless loop which is to be stopped.
while ~stoploop do
    .... whatever
end

                                          
 Adrian Weeks                             
 Development Engineer                     
                                          
                                          
 HID Global,                              
 3 Cae Gwyrdd,                            
 Green Meadow Springs                     
 Business Park,                           
 Cardiff CF15 7AB,                        
 United Kingdom.                          
 +44 (0)29 20528523                       
 (Office)                                 
 aweeks at hidglobal.com                     
 www.hidglobal.com                        
                                          





                                                                                                                                  
  From:       "Fahrni Pascal (fahn)" <fahn at zhaw.ch>                                                                               
                                                                                                                                  
  To:         "users at lists.scilab.org" <users at lists.scilab.org>                                                                   
                                                                                                                                  
  Date:       25/06/2014 21:15                                                                                                    
                                                                                                                                  
  Subject:    [Scilab-users] user terminate program (exit while loop)                                                             
                                                                                                                                  
  Sent by:    "users" <users-bounces at lists.scilab.org>                                                                            
                                                                                                                                  





Dear scilab users,

I’m using a scilab script to monitor a serial port, read from it and do
some calculations based on that data. The program is wrapped by a while
loop and contains an xpause statement. What is the best way to allow the
user to terminate the program by user input?

Best wishes
Pascal
 _______________________________________________
users mailing list
users at lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20140627/1f02ef0f/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 12445500.gif
Type: image/gif
Size: 4559 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20140627/1f02ef0f/attachment.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20140627/1f02ef0f/attachment-0001.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ecblank.gif
Type: image/gif
Size: 45 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20140627/1f02ef0f/attachment-0002.gif>


More information about the users mailing list