File:  [Local Repository] / tclpuks / prgsrc / puks.tcl
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Sat Aug 27 05:31:18 2005 UTC (18 years, 10 months ago) by boris
Branches: MAIN
CVS tags: HEAD
Now I can read the microprocessor

#!/usr/bin/wish
set DEVICE "/dev/ttyUSB0"

set SRLFILE [open $DEVICE r+]
fconfigure $SRLFILE -blocking 0  -translation binary -encoding binary -buffering none -mode  57600,n,8,1

set idle 0
set waiting 1

set state $idle


set buttoncode 256
for {set i 1} {$i <=8} {incr i} {
    set button($buttoncode) $i
    set buttoncode [expr $buttoncode*2]
}

proc readbuffer {} {
    global SRLFILE  button
    set key 0
    set message [read $SRLFILE]
    binary scan $message s key
    set key [expr $key & 0xFFFF]
    if {[catch {set key $button($key)}] == 0} {
	return $key
    }
    return 0
}

puts $SRLFILE s
after 200
readbuffer
puts $SRLFILE r
after 200
readbuffer



button .start -text "Start" -command start
pack .start
label .pressed 
pack .pressed


proc start {} {
    global SRLFILE state idle waiting
    readbuffer
    .start configure -state disabled -command {}
    set state $waiting
}

proc body  {} {
    global state idle waiting
    update idletasks
    if { $state == $waiting } {
	set pressed [readbuffer]
	if { $pressed != 0 } {
	    set state $idle
	    .start configure -state active -command start
	    .pressed configure -text "Pressed $pressed"
	    puts $pressed
	    readbuffer	}
    } else {
	readbuffer
    }
    after 10 body
}

body 






FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>