chiark / gitweb /
hexbin-term wip
[chiark-utils.git] / scripts / hexterm
1 #!/usr/bin/tclsh8.4
2
3 if {[llength $argv] != 1} { error "need serial port arg" }
4
5 set port [lindex $argv 0]
6
7 set port_stty [exec stty -F $port -g]
8 set term_stty [exec stty -g]
9
10 proc onreadp {} {
11     global p
12     while 1 {
13         set c [read $p 1]
14         
15 }
16
17 proc onreadk {} {
18 }
19
20 set e [catch {
21     exec stty          min 0 time 0 -istrip -ocrnl -onlcr -onocr -opost \
22                        -ctlecho -echo -echoe -echok -echonl -iexten -isig
23     exec stty -F $port min 0 time 0 -istrip -ocrnl -onlcr -onocr -opost \
24                        -ctlecho -echo -echoe -echok -echonl -iexten -isig \
25             9600 clocal cread -crtscts -hup -parenb cs8 -cstopb \
26             -ixoff bs0 cr0 ff0 nl0 -ofill -olcuc -onlcr
27     set p [open $port {RDWR|NONBLOCK} 0]
28     fconfigure $p -blocking false -buffering none
29     fconfigure stdin -blocking false -buffering none
30
31     fileevent stdin readable onreadk
32     fileevent $p readable onreadp
33 }]
34
35 fconfigure stdin -blocking true
36 exec stty $term_stty
37 exec stty -F $port $port_stty