Posted to tcl by patthoyts at Tue Apr 19 21:10:41 GMT 2011view raw
- proc tms_open {port} {
- variable TMSSettings
- set chan [open $port r+]
- fconfigure $chan -mode $TMSSettings \
- -buffering line -blocking 0 \
- -translation {cr cr}
- return $chan
- }
- proc tms_send {chan cmd} {
- puts -nonewline $chan "$cmd\r"
- flush $chan
- after 500 {set ::waiting_send 1} ; vwait ::waiting_send
- set limit 0
- while {[incr limit] < 10 && [gets $chan line] < 0} {
- after 100 {set ::waiting_send 1} ; vwait ::waiting_send
- }
- #puts "> $cmd\n< $line"
- return $line
- }
- proc tms_get {port} {
- variable tms_opened 1
- set tms [tms_open $port]
- if {[catch {
- set line [tms_send $tms T]
- } err]} {
- puts stderr "error: $err"
- }
- close $tms
- variable tms_opened 0
- binary scan $line c6a4 header hex
- return [format %.1f [expr {[scan $hex %x] / 10.0}]]
- }