Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Serial Port RS232

Posted by Yvanou (Yvanou), 11 May 2007

I have to develop a software in order to communicate  with a presure measurment device linked to a PC (Windows 95) with a RS232 serial port. I have to use tcl/tk language.

I can open the port "com2" with:

set com2 [open com2: r+]

I configure with fconfigure:

fconfigure $com2 -mode 9600,8,n,1 -buffering none -blocking 0

I try to send message and receive response...:

puts $com2 instruction
set resp [read $com2]
puts $resp

... but the device send me a blank line...

What can I do?  

I'm working on it for 3 days long.



Posted by admin (Graham Ellis), 11 May 2007
Because you've set blocking off, your read won't wait for andy input and you'll get an empty string back.

Posted by iamxiaop (iamxiaop), 16 July 2007
set tty [open /dev/ttyS0]
fconfigure $tty -mode 9600 0 8 2
set tty [open /dev/com1]

puts $iChannel "$username\r"; puts $iChannel "$password\r"
puts $iChannel "enable"


# 初始化串口
proc ComSetup {ComPort ComRate} {
  set iChannel [open $ComPort w+]
  set rate $ComRate
  fconfigure $iChannel -mode $ComRate,n,8,1
  fconfigure $iChannel -blocking 0
  fconfigure $iChannel -buffering none
  fileevent $iChannel readable ""
  return $iChannel

# 从串口读取数据
proc GetData {iChannel} {
  global output
  after 2000
  set cap [read -nonewline $iChannel]
  return "$cap"  
# 向串口中写数据
proc SendCmd {channel command} {
  global output debug

  set letter_delay 10  
  set commandlen [string length $command]
  for {set i 0} {$i < $commandlen} {incr i} {  
     set letter [string index $command $i]
     after $letter_delay
     puts -nonewline $channel $letter
     if {$debug(dutConfig) == 1} {puts -nonewline $output "$letter"}
  after $letter_delay  
  puts -nonewline $channel "\n"
  if {$debug(dutConfig) == 1} {puts $output ""}
  after 500
  flush $channel
  package require Expect
  set hostname
  set password admin

  exp_spawn telnet $hostname
  expect "*Password:" {exp_send "$password\n"}
  expect "*>"         {exp_send "en\n"}
  expect "Password:"  {exp_send "$password\n" }
  # Do More ...

Posted by iamxiaop (iamxiaop), 16 July 2007;action=display;num=1138163407;start=0

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho