The following lines work fine under Windows. To send a string, just call
puts $port_id $stringToSend
Good Luck.
set baudRate 38400
set port_id [open "com1" "RDWR"]
fconfigure $port_id -blocking 0 -buffersize 10000 -mode $baudRate,n,8,1 -translation crlf
set func_name "processData"
fileevent $port_id readable {
$func_name
}
# processData --
#
# Processing the data received from the serial port
# and put the input string to the text box, .t here.
#
proc processData {} {
global port_id
global initial mod_index act_mod
global a_line
global mod_list file_name curr_mod
global cmd_queue cmd_ready cmd_pointer
global inEscSeq escCmdStr chEsc chRt lnFd
global escSeq clrScreen clr2EndLine
global iRow iCol
global w
global base page_length back2main
global bufferLength
set rx_char [read $port_id]
append a_line $rx_char
# regsub -all \x08 $rx_char "\b" rx_char; # replace BS
# puts $rx_char
while {[string is print -failindex firstCtrl $rx_char] == 0} {
if {$firstCtrl > 0} {
set tempStr [string range $rx_char 0 [expr $firstCtrl - 1]]
.t_ insert end $tempStr
.t_ mark set insert end
.t_ see insert
}
set char [string index $rx_char $firstCtrl]
if {$char == "\b"} {
.t_ delete [.t_ index "end - 2 chars"] end
# .t_ delete 0.0 end
.t_ mark set insert end
.t_ see insert
} else {
.t_ insert end $char
.t_ mark set insert end
.t_ see insert
}
incr firstCtrl
set rx_char [string range $rx_char $firstCtrl end]
if {$rx_char == ""} {
break
}
}
.t_ insert end $rx_char
.t_ mark set insert end
.t_ see insert
set lines [lindex [.t_ index end] 0]
if {$lines > $bufferLength} {
.t_ delete 0.0 [.t_ index "end - $bufferLength lines"]
}
if {$rx_char != " "} {
set cmd_ready 0
}
if {$rx_char == $chEsc} {
set inEscSeq 1
set escCmdStr ""
}
}