Posted to tcl by jbeale123 at Wed Jul 20 18:18:50 GMT 2011view raw
- # For COMn with n>9, you must use the Win32 device name e.g. {\\.\COM14}
- ############################################
- # Example (1): Poll the comport periodically
- # set serial [open \\.\COM14 r+]
-
- proc serdisp { } {
- set serial [open "COM9:" r+]
- # fconfigure $serial -mode "115200,n,8,1"
- fconfigure $serial -mode "9600,n,8,1"
- fconfigure $serial -blocking 1 -timeout 100 -buffersize 50
-
- for {set i 0} {$i < 20} {incr i} {
- set data [read $serial] ;# read ALL incoming bytes
- set size [string length $data] ;# number of received byte, may be 0
- if { $size } {
- puts "received $size bytes: $data"
- } else {
- puts "<no data>"
- update ;# Display output, allow to close wish-window
- }
- }
- }
-
- # display data coming in on serial port
- serdisp
-