1 | #!/usr/bin/expectk |
---|
2 | |
---|
3 | ################################## |
---|
4 | ## Talk to tilt controller on bt5 |
---|
5 | ## |
---|
6 | ## Andrew Jackson, April 2007 |
---|
7 | ################################## |
---|
8 | |
---|
9 | package require Tix |
---|
10 | |
---|
11 | proc exec_cmd {cmd_text} { |
---|
12 | global tf |
---|
13 | |
---|
14 | $tf.output insert end "$cmd_text\n" |
---|
15 | exp_send "$cmd_text\r" |
---|
16 | |
---|
17 | } |
---|
18 | |
---|
19 | |
---|
20 | proc goButProc {changeVal} { |
---|
21 | global tf |
---|
22 | |
---|
23 | $tf.output insert end "REL A1 $changeVal G\n" |
---|
24 | exp_send "REL A1 $changeVal G\r" |
---|
25 | |
---|
26 | } |
---|
27 | |
---|
28 | log_user 0 |
---|
29 | set port /dev/ttyS0 |
---|
30 | set serialid [spawn -noecho -open [open $port w+]] |
---|
31 | set baud 19200 |
---|
32 | #stty ispeed $baud ospeed $baud -raw cs8 -parenb -cstopb < $port |
---|
33 | stty -F $port ispeed $baud ospeed $baud raw icrnl |
---|
34 | |
---|
35 | |
---|
36 | #Build GUI |
---|
37 | #Create main frame |
---|
38 | frame .fmain |
---|
39 | |
---|
40 | #Create Notebook tabs |
---|
41 | set nb [tixNoteBook .fmain.noteb] |
---|
42 | $nb add simple -label "Tilt Adjust" -underline 0 |
---|
43 | $nb add tiltterm -label "Command line" -underline 0 |
---|
44 | #Get frames for each tab |
---|
45 | set simpletab [frame [$nb subwidget simple].f] |
---|
46 | set termtab [frame [$nb subwidget tiltterm].f] |
---|
47 | |
---|
48 | |
---|
49 | #Populate simple tab |
---|
50 | set sf [frame $simpletab.sframe -background grey] |
---|
51 | |
---|
52 | pack [tixLabelEntry $sf.motorval -label "Number of clicks"] -padx 10 -pady 10 |
---|
53 | pack [button $sf.gobut -text "Change Tilt"\ |
---|
54 | -command {goButProc [ [$sf.motorval subwidget entry] get] } ]\ |
---|
55 | -padx 10 -pady 10 -anchor s |
---|
56 | pack $sf -fill both -expand true |
---|
57 | |
---|
58 | #Populate term tab |
---|
59 | set tf [frame $termtab.tframe] |
---|
60 | |
---|
61 | pack [text $tf.output] -fill both -anchor nw -expand true |
---|
62 | pack [entry $tf.cmdentry] -side left -fill x -expand true -anchor w |
---|
63 | pack [button $tf.verbut -text "Execute Command"\ |
---|
64 | -command { exec_cmd [$tf.cmdentry get] } ]\ |
---|
65 | -side right |
---|
66 | |
---|
67 | pack $tf -fill x |
---|
68 | |
---|
69 | #Pack up and go |
---|
70 | pack $nb $simpletab $termtab -fill both -expand true |
---|
71 | pack .fmain -fill both -expand true -anchor nw |
---|
72 | |
---|
73 | exp_send "\r" |
---|
74 | expect -re ">" { $tf.output insert end $expect_out(buffer) |
---|
75 | exec_cmd "VER" |
---|
76 | } |
---|
77 | expect -re ">" { $tf.output insert end $expect_out(buffer) |
---|
78 | exec_cmd "CHL A1=0" |
---|
79 | } |
---|
80 | expect -re ">" { $tf.output insert end $expect_out(buffer) |
---|
81 | exec_cmd "VEL A1 0=100" |
---|
82 | } |
---|
83 | expect -re ">" { $tf.output insert end $expect_out(buffer) |
---|
84 | exec_cmd "VEL A1 0" |
---|
85 | } |
---|
86 | expect -re ">" { $tf.output insert end $expect_out(buffer) |
---|
87 | exec_cmd "ACC A1 0" |
---|
88 | } |
---|
89 | expect -re ">" { $tf.output insert end $expect_out(buffer) } |
---|
90 | |
---|
91 | expect_background { |
---|
92 | -re ">" { |
---|
93 | $tf.output insert end $expect_out(buffer) |
---|
94 | } |
---|
95 | -re "\\?" { |
---|
96 | $tf.output insert end $expect_out(buffer) |
---|
97 | } |
---|
98 | } |
---|