If you could give some specific examples or refer me to a good
reference, I would appreciate it. P.S.- I have read most of the
Ousterhout book but haven't found any description so far.
Sent via Deja.com http://www.deja.com/
Before you buy.
You have to do something like:
set serial [open "COM1:" r+]
and then $serial is a channel to the com port.
> reference, I would appreciate it. P.S.- I have read most of the
> Ousterhout book but haven't found any description so far.
The Ousterhout predates serial device support, along with many other
features. I highly recommend getting the latest (3rd) edition of
Brent Welch's Practical Programming in Tcl and Tk.
--
Jeffrey Hobbs The Tcl Guy
hobbs at ajubasolutions.com Ajuba Solutions (née Scriptics)
Its opens and configure the serial port
[open ...] [fconfigure ...]
A event handler is defined for incoming characters from the serial
port
[fileevent $chan readable receiver].
And a keyboard event is specified for typed characters to be sent
to the serial port
[bind ...].
Regards,
Rolf
ray...@my-deja.com wrote:
>
> Hello. My appliation requires that I open the COM1 port on my PC as
> a file using Tk. The idea is to setup a frame widget that operates
> similar to the HyperTerm application under Windows. The application
> I'm trying to control is a simple "dumb term", serial I/O (console
> display, keyboard response) type. Once I have the frame set up with
> the correct display, I plan to control the keyboard input through
> buttons, command menus, etc. OK??
>
> If you could give some specific examples or refer me to a good
> reference, I would appreciate it. P.S.- I have read most of the
> Ousterhout book but haven't found any description so far.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
---------------------------------------------------------------------
German Aerospace Center Rolf Schroedter
Inst. of Planetary Exploration Tel/Fax: +49 (30) 67055-416/384
Rudower Chaussee 5, D-12489 Berlin Internet: Rolf.Sc...@dlr.de
"couldn't open "com1", permission denied"
I also tried the following:
set chan [open "COM1:" r+] (vs. set chan [open com1 r+])
but still get the same error msg.
I am using Windows NT system and have no terminal windows (e.g.,
HyperTerm) open. Also, tried on Win98 system with same results.
Any ideas/suggestions?
You may also have an unclosed wish pending.
Typically I get those things with:
console show
wm withdraw .
set chan [open com1 r+]
# if you now don't close the console-window with [exit] or "File-Exit"
# but wth a click onto [x] you'll have a dead wish83 hanging.
Rolf.
--
In proc term_in, there is a failure to process line 11 when I start
receiving characters. The exact command WISH83 complains about is
"$txt see end".
Also, I could not get the frame to display at all until I broke up
the command:
set Term(Text) [scrolled_text .t -width 80 -height 25 -font Courier ] \
pack .t -side top -fill both -expand true
Had to break it into two seperate lines (just like above w/o the \
delimiter).
Any ideas/suggestions what to try next? (Thanks!)
I can't understand what happened. For me the program works (Tcl822).
"$txt see end" works fine for me.
Also I don't have merged lines as you had.
Did the mail-program mangle the file ?
Here is the source again, today not as an attachment,
but with Copy&Paste.
file SimpleTerm.tcl:
###############################################################################
# Term for a simple terminal interface
# !!! fileevent funktioniert NICHT mit Term unter Win95 !!!
# --> Polling
###############################################################################
# The terminal bindings are implemented by defining a new bindtag 'Term'
###############################################################################
set Term(Text) {}
##################### Terminal In/Out events ############################
proc term_out { chan key } {
switch -regexp -- $key {
[\x07-\x08] -
\x0D -
[\x20-\x7E] { puts -nonewline $chan $key; return -code break }
[\x01-\x06] -
[\x09-\x0C] -
[\x0E-\x1F] -
\x7F { return }
default { return }
} ;# switch
}
proc term_in { ch } {
upvar #0 Term(Text) txt
switch -regexp -- $ch {
\x07 { bell }
\x0A { # ignore }
\x0D { $txt insert end "\n" }
default { $txt insert end $ch }
}
$txt see end
}
proc receiver {chan} {
foreach ch [ split [read $chan] {}] {
term_in $ch
}
}
##################### Windows ############################
proc scrolled_text { f args } {
frame $f
eval {text $f.text \
-xscrollcommand [list $f.xscroll set] \
-yscrollcommand [list $f.yscroll set]} $args
scrollbar $f.xscroll -orient horizontal \
-command [list $f.text xview]
scrollbar $f.yscroll -orient vertical \
-command [list $f.text yview]
grid $f.text $f.yscroll -sticky news
grid $f.xscroll -sticky news
grid rowconfigure $f 0 -weight 1
grid columnconfigure $f 0 -weight 1
return $f.text
}
##### main #######
set chan [open com1 r+]
fconfigure $chan -mode "19200,n,8,1" -translation binary -buffering none -blocking 0
fileevent $chan readable [list receiver $chan]
set Term(Text) [scrolled_text .t -width 80 -height 25 -font Courier ]
pack .t -side top -fill both -expand true
bind $Term(Text) <Any-Key> [list term_out $chan %A]
console hide
> I can't understand what happened. For me the program works (Tcl822).
> "$txt see end" works fine for me.
> Also I don't have merged lines as you had.
> Did the mail-program mangle the file ?
> Here is the source again...
Got it working, thanks to Rolf for a great little script.
I had a couple of little problems, as follows:
1) On my system, for some reason you have to startup a HyperTerm
window first and establish your connection. Then just exit HyperTerm
and start the script. Else I get "fail to open com1" as described
previously. Why, I dunno...
2) My shell doesn't like like the pack statement on the same line with
set or the fileevent statement on the same line with fileconfig at
the end of the script so just seperated them.
3) Changed from 19200 to 9600 baud for my target system (but this
is no-brainer..)
3) Pasted below is my final working version with above changes FYI:
########################################################################
#
# Term for a simple terminal interface
# !!! fileevent funktioniert NICHT mit Term unter Win95 !!!
# --> Polling
########################################################################
#
# The terminal bindings are implemented by defining a new bindtag 'Term'
########################################################################
#
set Term(Text) {}
return $f.text
}
fconfigure $chan -mode "9600,n,8,1" -translation binary -buffering none
-blocking 0
fileevent $chan readable [list receiver $chan]
set Term(Text) [scrolled_text .t -width 80 -height 25 -font Courier ]
pack .t -side top -fill both -expand true
bind $Term(Text) <Any-Key> [list term_out $chan %A]
console hide