#!/usr/bin/expectk ################################## ## Talk to tilt controller on bt5 ## ## Andrew Jackson, April 2007 ################################## package require Tix proc exec_cmd {cmd_text} { global tf $tf.output insert end "$cmd_text\n" exp_send "$cmd_text\r" } proc goButProc {changeVal} { global tf $tf.output insert end "REL A1 $changeVal G\n" exp_send "REL A1 $changeVal G\r" } log_user 0 set port /dev/ttyS0 set serialid [spawn -noecho -open [open $port w+]] set baud 19200 #stty ispeed $baud ospeed $baud -raw cs8 -parenb -cstopb < $port stty -F $port ispeed $baud ospeed $baud raw icrnl #Build GUI #Create main frame frame .fmain #Create Notebook tabs set nb [tixNoteBook .fmain.noteb] $nb add simple -label "Tilt Adjust" -underline 0 $nb add tiltterm -label "Command line" -underline 0 #Get frames for each tab set simpletab [frame [$nb subwidget simple].f] set termtab [frame [$nb subwidget tiltterm].f] #Populate simple tab set sf [frame $simpletab.sframe -background grey] pack [tixLabelEntry $sf.motorval -label "Number of clicks"] -padx 10 -pady 10 pack [button $sf.gobut -text "Change Tilt"\ -command {goButProc [ [$sf.motorval subwidget entry] get] } ]\ -padx 10 -pady 10 -anchor s pack $sf -fill both -expand true #Populate term tab set tf [frame $termtab.tframe] pack [text $tf.output] -fill both -anchor nw -expand true pack [entry $tf.cmdentry] -side left -fill x -expand true -anchor w pack [button $tf.verbut -text "Execute Command"\ -command { exec_cmd [$tf.cmdentry get] } ]\ -side right pack $tf -fill x #Pack up and go pack $nb $simpletab $termtab -fill both -expand true pack .fmain -fill both -expand true -anchor nw exp_send "\r" expect -re ">" { $tf.output insert end $expect_out(buffer) exec_cmd "VER" } expect -re ">" { $tf.output insert end $expect_out(buffer) exec_cmd "CHL A1=0" } expect -re ">" { $tf.output insert end $expect_out(buffer) exec_cmd "VEL A1 0=100" } expect -re ">" { $tf.output insert end $expect_out(buffer) exec_cmd "VEL A1 0" } expect -re ">" { $tf.output insert end $expect_out(buffer) exec_cmd "ACC A1 0" } expect -re ">" { $tf.output insert end $expect_out(buffer) } expect_background { -re ">" { $tf.output insert end $expect_out(buffer) } -re "\\?" { $tf.output insert end $expect_out(buffer) } }