########################## # Program: feedback_pipe # # receives any messages from stdin and send them # using the "send" command to the production cell simulation ########################## #------------------------------------------------------------------------------ # This file was modified by Hubert Garavel - Wed Sep 25 10:03:02 CEST 2013 #------------------------------------------------------------------------------ # Set the variable monitor to 1, if all messages handled by feedback_pipe # should be reported to stdout additionaly ; 0 else set monitor 0 if {[lsearch $argv -dbg] != -1} {set monitor 1} package require comm # Wait until tksim_9 has written file $env(SOCKET_FILE) set file_not_ready 1 while { $file_not_ready } { after 100 set file_not_ready [ catch { open "$env(SOCKET_FILE)" "r" } fd ] # here, two cases are possible : # - file_not_ready = 0, fd = file5 (or file6...) # - file_not_ready = 1, fd = "couldn't open ..." if {$monitor} { puts stdout "FEEDBACK_PIPE: file_not_ready = $file_not_ready, fd = $fd" } } # Read tksim_9's socket number from file $fd and remove this file set socket [gets $fd] close $fd file delete "$env(SOCKET_FILE)" if {$monitor} { puts stdout "FEEDBACK_PIPE: socket = $socket" } # Window manager configuration wm title . FP wm withdraw . set stop 0 while { !$stop } { gets stdin zeile set counter 1 if {[eof stdin]} \ then {set stop 1} \ else { if {$monitor} { puts stdout "FEEDBACK_PIPE: sending <<< $zeile >>> to socket $socket" } # Catch send-errors if any occured while { [catch {comm::comm send $socket $zeile}] == 1} { if {$monitor} { puts stdout "FEEDBACK_PIPE: Interpreter didn't respond" } # Wait for a second after 1000 if {$monitor} { puts stdout "FEEDBACK_PIPE: I'll wait one more time" } if { [incr counter] == 3 } { if {$monitor} { puts stdout "FEEDBACK_PIPE: Interpreter didn't respond to long -- I QUIT" } set stop 1 break } } } } destroy . exit