3 # tip.tcl is like a simple version of cu, written in pure Jim Tcl
4 # It makes use of the new aio tty support
6 # Note: On Mac OS X, be sure to open /dev/cu.* devices, not /dev/tty.* devices
9 {Usage
: tip ?settings? device
12 Where settings are as follows
:
13 1|
2 stop bits
(default 1)
14 5|
6|
7|
8 data bits
(default 8)
15 even|odd parity
(default none
)
16 xonxoff|rtscts handshaking
(default none
)
17 <number
> baud rate
(default 115200)
19 e.g. tip
9600 8 1 rtscts
/dev
/ttyUSB0
}
36 if {[string match
-h* $i] ||
[string match help
* $i]} {
40 if {$i in
{even odd
}} {
41 set settings
(parity
) $i
44 if {$i in
{ixonixoff rtscts
}} {
45 set settings
(handshake
) $i
52 if {$i in
{5 6 7 8}} {
56 if {[string is integer
-strict $i]} {
60 if {[file exists
$i]} {
64 puts "Warning: unrecognised setting $i"
67 if {![exists device
]} {
72 # save stdin and stdout tty settings
73 # note that stdin and stdout are probably the same file descriptor,
74 # but it doesn't hurt to treat them independently
75 set stdin_save
[stdin tty
]
76 set stdout_save
[stdout tty
]
79 set f
[open $device r
+]
81 puts "Failed to open $device"
86 puts "Device is in use: $device"
97 puts "\[$device\] Use ~. to exit"
105 stdout tty output raw
106 stdout buffering none
117 set status
"$device: disconnected"
120 stdout
puts -nonewline $c
124 proc tilde_timeout
{} {
134 # may receive more than one char here, but only need to consider
135 # ~. processing if we receive them as separate chars
136 if {$tilde == 0 && $c eq
"~"} {
138 # Need ~. within 1 second of each other
139 after 1000 tilde_timeout
142 after cancel tilde_timeout
150 $f puts -nonewline $c
156 # restore previous settings
157 stdin tty
{*}$stdin_save
158 stdout tty
{*}$stdout_save