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: is my code wrong or something else?

Posted by jschna1 (jschna1), 17 July 2007
Currently I need to send some commands down a serial port but when I send them nothing happens.  Then I tried using fconfigure -mode to set the mode, but it throws an error that mode is not an acceptable argument (like its not recognizing the device as a serial port).  And to top it off, when I try to read from the device the program just freezes indefinately.

Below is that section of my code, but the question is: is this code wrong or is my computer not able to communicate this way bc of the OS or tcl/tk version?  I am running a Red Had Linux machine with tcl/tk 8.3 on it.

set port [open /dev/ttyS4 w+]  
##I tried w+, r+, w, and r and never got it to work right.

fconfigure $port -mode "9600,n,8,1"
##the rest doesnt work without the fconfigure but
##fconfigure throws error when it is included.

puts $port "pos=1\n"
#puts just doesn't seem to send the command at all

set myData [read $port 1] #get 1 char
#the read freezes the window

close $port

Posted by admin (Graham Ellis), 17 July 2007
That fconfigure look very windows-like ...

Posted by jschna1 (jschna1), 17 July 2007
This is what I get from the man page of open.

"If fileName refers to a serial port, then the specified serial port is opened and initialized in a platform-dependent manner. Acceptable values for the fileName to use to open a serial port are described in the PORTABILITY ISSUES section.
The fconfigure command can be used to query and set additional configuration options specific to serial ports (where supported):

-mode baud,parity,data,stop
This option is a..." (then it goes on to talk about all the other options and such)

and then in the Portability Issues section:
"Valid values for fileName to open a serial port are generally of the form /dev/ttyX, where X is a or b, but the name of any pseudo-file that maps to a serial port may be used. Advanced configuration options are only supported for serial ports when Tcl is built to use the POSIX serial interface. "

But I think that Red Hat is POSIX compatible, so that shouldn't be the problem, should it?

Posted by admin (Graham Ellis), 18 July 2007
Have you tried the POSIX open?

set port [open /dev/ttyS4 RDWR]

Posted by jschna1 (jschna1), 18 July 2007
I have; I even tried again thinking maybe I was wrong but same things happen: when writing nothing happens and the program freezes when reading.

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