I wonder if anyone can give me a hint on event processing on serial
ports.
This is Tcl/Tk 8.2.2 on Windows 98. I would like to handle incoming
data
event driven, and have opened the serial port this way:
if [catch {
set commPortFile [open $commPort "r+"]
fconfigure $commPortFile -encoding binary
fconfigure $commPortFile -translation {binary binary}
fconfigure $commPortFile -buffering none
fconfigure $commPortFile -blocking NO
if {[string length $modeData] > 1} {
set oldMode [fconfigure $commPortFile -mode]
fconfigure $commPortFile -mode $modeData
}
fileevent $commPortFile readable $readFunction
} result] {
diagOut "\nError opening or configuring serial port: $result\n"
}
I get no errors from any of this, but my "$readFunction" is never
envoked,
even though I can watch data on the line with a monitor. $commPortFile
is
correct, because I watch my data going out, and the device responds to
it.
For what it is worth, this is the stub readFunction:
proc diagSerialInput {} {
puts "\nIn SerialInput"
global commPortFile
if [eof $commPortFile] {
close $commPortFile
set commPortFile ""
return
}
set data [gets $commPortFile]
diagOut "\ndata received: $data"
}
Can anyone shed light on what I'm doing wrong? Thanks for the help.
Al Folsom
--
---------------------------------------------------------
Alan L. Folsom, Jr. Phone:215 628-0840
PO Box 481, 904 Sheble Lane Fax: 215 628-0353
Spring House, PA 19477 fol...@jmisoftware.com
---------------------------------------------------------
http://mini.net/cgi-bin/wikit/447.html
I think your problem is that you're calling [gets ...] on a channel
that has buffering turned off and no line translation. You should
*really* be using [read ...].
fileevent readable guarantees one of the following: 1) eof, or
2) a [read ...] will return at least one byte. There are *no*
guarantees about the behavior of [gets ...], which is highly
dependent on the -translation mode of the channel.
-=- D. J.
Sent via Deja.com http://www.deja.com/
Before you buy.