GETPOSN {
while {} {
... assign values to global variables
}
}
values are returned from a server program in the while loop and these values are
assigned to global variables to be used in the execution of the program .. is there a
way I can make the procedure GETPOSN run in the background ??
ps : I'm new to Tcl .. TIA for any help ...
--
.__J.a.M.E.s...c.0.R.n..000..000..111.__.
: email: james...@pobox.org.sg :
:_web: http://www.iscs.nus.sg/~tanpuayh_:
No, at least in standard Tcl.
I think the BLT extensions provide a way to evaluate scripts in the background.
I guess you use sockets to communicate with the server. In this case you can use
fileevents on sockets, in order to call a handler in the background each time the
server sends a value.
Regards, Fred
--
Frederic BONNET Eleve-Ingenieur de l'Ecole des Mines de Nantes
fbo...@irisa.fr Stagiaire IRISA - Projet Solidor
"Il ne faut jamais remettre au lendemain ce qu'on peut faire le surlendemain"
Oscar WILDE
something to add on ... I would like GETPOSN to run in the background, or better
still, to run as a separate thread that is created at the start of the program.. is there
a way to do this ??.. TIA.
JaMEs> Hi all..
JaMEs> let's say I have a self-defined Tcl procedure GETPOSN :
JaMEs> GETPOSN {
JaMEs> while {} {
JaMEs> ... assign values to global variables
JaMEs> }
JaMEs> }
JaMEs> values are returned from a server program in the while loop and these values are
JaMEs> assigned to global variables to be used in the execution of the program .. is there a
JaMEs> way I can make the procedure GETPOSN run in the background ??
Look at 'after' command to push procedure on the event queue.
-Yves
--
Yves Mathys Europe Design Technology
mat...@ssdtgva.sps.mot.com High Level Modeling
Motorola Inc
Phone: (41-22) 799 12 28 207, route de Ferney/CP 15
FAX: (41-22) 799 13 04 1218 Grand-Saconnex,Switzerland
You are not thinking in event-based terms.
If the values from the server are arriving on channel ServerChan (a
socket or pipe), then you want to arrange for a procedure to be called
every time a new value is available from ServerChan. This means that
you need to do a bit of coding with fileevent
proc getOnePosn {} {
global ServerChan
if {[gets $ServerChan line] < 0} {
close $ServerChan
# The server has gone away!?
} else {
# ... Do Something with the line just read ...
}
}
fileevent $ServerChan readable getOnePosn
Now you need to make sure that you enter the Tcl event loop (Tk event
loop for 7.4/4.0) using tkwait or vwait.
Donal.
--
Donal K. Fellows, (at work) | Donal K. Fellows, (at home)
Dept. of Computer Science, | 6, Randall Place, Heaton,
University of Manchester | Bradford, BD9 4AE
U.K. Tel: ++44-161-275-6137 | U.K. Tel: ++44-1274-401017
fell...@cs.man.ac.uk (preferred) | do...@ugglan.demon.co.uk (if you must)
--------------------------------------------------------------------------
<http://r8h.cs.man.ac.uk:8000/> for my home page
Maybe it's even not such a very good idea to modify global variables from
the background ... How about using the 'send'-command from a seperate script,
which can be started like: exec ListenToServer.tcl
You could implement callback functions for received data and call them
remotely via the send-command (see man-page).
Another way to perform background tasks is to use the 'after'-command:
proc SayHi {} {
puts stdout 'Hi there'
after 1000 SayHi
}
SayHi
Bye,
--
Nenad Cimerman
+---------------------------------------------------------------------------+
| Nenad Cimerman, Informatiker Abteilung EM (EM Dept.) |
+---------------------------------------+-----------------------------------+
| H.Stoll GmbH & Co. | phone : +49 (0)7121/313-346 |
| Stollweg 1 | fax : +49 (0)7121/313-110 |
| 72760 Reutlingen (Germany) | e-mail: ni...@stoll.de |
+---------------------------------------+-----------------------------------+