Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Serial communication and tcl control (i'm a newbie sorry!!)

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm trying to automate a test process that brings up three hyperterminals and requires a lot of user interaction. I've been looking at tcl/expect(Windows NT version of tcl/expect) to automate this process for me however, I am stuck. I am able to spawn off the hyperterminal process, however I am unsure how to switch control over to the hyperterm so I can actually do the automation. I've looked through a couple of books and scanned the man pages and I can't find anything on it. This may be really easy, but due to my inexperice I'm stuck. Can tcl/tk/expec do this and if so what is the neccesary steps. Any help would be greatly appreciated!! Thanks!
 
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 ""
}
}

 
Thanks for your reply, I really appreciate the help!!
I'll give it a shot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top