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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Serial port communication

Status
Not open for further replies.

HardeepS

Technical User
Apr 6, 2005
1
CA
Hi. I was writing a script to read/write to a serial port connection and I am having a lot of problems with it. The device is a terminal device (ie. cisco router) and I want to use this tcl script to issue commands and get back the output from those commands. I am connected at a baudrate of 115200. I read that if I'm using a fast connection speed, I should increase the buffer size.

So, I open the serial connection using "open com1: r+". Then I use the fconigure command like "fconfigure $conSock -mode 115200,n,8,1 -blocking 0 -buffering line -sysbuffer 100000". Thing is, when I issue a command on the device which has a lot of output and I issue a "gets", I get an error. I'm not 100% sure how to use the serial connection properly or if the options in my fconfigure are correct. If anyone could help me understand how the input.output to the device is buffered and actually works or point me towards a good document about information on this, it would be much appreciated.

Thanks in advance.
 
I'm having the same type of question. I have some specific errors .. please see below

----
OS: Windows Vista Premium
Tcl Version: 8.4

Goal: Looking for write capabilities with Serial Port.

Code:

# In Windows, we open a channel with "com1"
=>set com [open com1: w]
file14c4158
# Configure the channel as per what we want.
=>fconfigure $com -mode 9600,n,8,1 -blocking 0 -translation auto -buffering line
# Try to write the string "hi" on the channel
=>puts $com "hi"
can not find channel named "file14c4158"
=>


Any ideas why I'm getting this error?
If I open the same com1 channel for w+ access, (read and write), I'm able to READ the channel, but still not write to it.


Thanks!
 
Not sure about your exact use, but this works for me:
fconfigure $port -mode 19200,n,8,1 -blocking 0 -translation auto -buffering none -handshake xonxoff
(Change the baud rate to what you are using.)
More code, if needed:
This works great with the text widget for a gui capture:
proc bkLog {} {
global port
set port [open "com1:" r+]
fconfigure $port -mode 19200,n,8,1 -blocking 0 -translation auto -buffering none -handshake xonxoff
fileevent $port readable [list rd_port $port]
set portFlag 1
puts -nonewline $port "\xd"
}
proc rd_port {port} {
$test.b insert end [read $port]
$test.b see insert
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top