Linux system freezes/hangs when using Tcl serial port

Linux system freezes/hangs when using Tcl serial port

Post by bruwillima » Sun, 07 Oct 2007 01:32:12


I'm running linux (uname output is "Linux epgd157 2.4.21-37.ELsmp #1
SMP Wed Sep 7 13:28:55 EDT 2005 i686 i686 i386 GNU/Linux") , Tcl
version 8.3 on an HP xw8400 workstation. My linux system freezes
entirely after an apparently random amount of time when I run a Tcl
script that continuously writes to and reads from /dev/usb/ttyUSB0/
(using a USB to serial converter).

The script I'm using to reproduce this (doesn't really do anything
useful) sends a command to a device via the serial port, then waits
for a half second while the response from the device is read in (the
response is about 1000 bytes and takes less than a half second to read
in). This is repeated until eventually my system freezes (can take an
hour or less up to a couple of days before my system freezes). This
has also been reproduced with Tcl 8.4.14.

Here's the script:

#*************************************************************************
proc get_response {} {
global SRLFILE

while { ![eof $SRLFILE] } {
set data [read $SRLFILE 1]
if { $data == "" } break
}
}

set SRLFILE [open /dev/usb/ttyUSB0 RDWR]

#Configure the device file using the baud, parity, ...
fconfigure $SRLFILE -blocking 0 \
-mode 115200,n,8,1 \
-translation binary \
-buffering none

#bind file readable events to the get_output procedure
fileevent $SRLFILE readable get_response

set cmd "this gets sent to serial port"

while { 1 } {
# Slow down send to at most one byte per millisecond
for { set ind 0 } { $ind < [string length "$cmd"] } { incr ind } {
puts -nonewline $SRLFILE [string index "$cmd" $ind]
set x 0
after 1 set x 1
vwait x
}
puts -nonewline $SRLFILE \n

# wait a half second for response to be read in (this is plenty of
time)
set x 0
after 500 set x 1
vwait x
}
#*****************************************************************************


Any idea why my entire Linux system appears to be totally frozen - no
input, output, network, etc.?
 
 
 

Linux system freezes/hangs when using Tcl serial port

Post by Uwe Klei » Sun, 07 Oct 2007 02:12:53


Hi

What happens when you do some other IO stuff instead of your testcase?
Does it lock up too?
Have you had a look around on lkml or other linux sites where an
error like that might have been posted?

uwe

 
 
 

Linux system freezes/hangs when using Tcl serial port

Post by ZB » Sun, 07 Oct 2007 02:14:19

Dnia 05.10.2007 Ralf Fassel < XXXX@XXXXX.COM > napisaa:
>> * XXXX@XXXXX.COM >>| proc get_response {} { >>| global SRLFILE >>| >>| while { ![eof $SRLFILE] } { >>| set data [read $SRLFILE 1] >>| if { $data == "" } break >>| } >>| } >> >> You should 'close' the file descriptor in case of EOF,

Actually, there's no "close" in the procedure above. Could you be more
specific?

I'm not sure - did you mean: EOF makes "automatic close"?
>> otherwise the fileevent triggers again and again. EOF >> should not happen for a RS232, but...

What is the cause of that "endless triggering"?
--
ZB
 
 
 

Linux system freezes/hangs when using Tcl serial port

Post by Ralf Fasse » Sun, 07 Oct 2007 02:14:36

* XXXX@XXXXX.COM
| proc get_response {} {
| global SRLFILE
|
| while { ![eof $SRLFILE] } {
| set data [read $SRLFILE 1]
| if { $data == "" } break
| }
| }

You should 'close' the file descriptor in case of EOF, otherwise the
fileevent triggers again and again. EOF should not happen for a
RS232, but...

| # Slow down send to at most one byte per millisecond

Why this? You're using the highest baudrate and then slowing down
the transfer artificially?

| Any idea why my entire Linux system appears to be totally frozen -
| no input, output, network, etc.?

Might be a driver problem. Which Serial-to-USB converter do you use?
Anything in the syslog?

R'
 
 
 

Linux system freezes/hangs when using Tcl serial port

Post by ZB » Sun, 07 Oct 2007 02:20:39

Dnia 05.10.2007 Ralf Fassel < XXXX@XXXXX.COM > napisaa:
>> You should 'close' the file descriptor in case of EOF

Sorry, never mind - I overlooked, that you wrote "should", not
"shouldn't"... too much apostrophes. :]
--
ZB
 
 
 

Linux system freezes/hangs when using Tcl serial port

Post by bruwillima » Sun, 07 Oct 2007 04:01:24


Yep, but this isn't production code. It's just being used to
reproduce the issue.


The data being sent to the device is normally typed by hand by a
user. I'm working on a script that can send preset data, which would
be sent much faster. I noticed that the device was sometimes dropping
data if sent at the fast rate. It looks like the device's input
buffer is getting filled faster than it can empty it, so I slowed the
send rate down artificially. This is similar to what the "-s" flag in
the expect "send" command does.


I suspect a driver problem, too, but I have little experience to deal
with these. I'm using the Keyspan USA-49WLC converter. It doesn't
look like our sys admin wants us viewing the syslog (permission
denied).
 
 
 

Linux system freezes/hangs when using Tcl serial port

Post by Uwe Klei » Sun, 07 Oct 2007 04:05:13


try "dmesg"
uwe
 
 
 

Linux system freezes/hangs when using Tcl serial port

Post by bruwillima » Sun, 07 Oct 2007 04:08:11

> What happens when you do some other IO stuff instead of your testcase?

I've tried other output (e.g. stdout) withtout any problem. I've not
tried other input. I'll try using /dev/ttyS0 (no USB-serial
converter) and see if the problem still happens.


I did some searches, but didn't find anything obvious (to me).

Thanks!
 
 
 

Linux system freezes/hangs when using Tcl serial port

Post by Jan Kandzi » Sun, 07 Oct 2007 04:26:35


XXXX@XXXXX.COM schrieb:
Using handshake (RTS/CTS or XON/XOFF on a 3-wire cable) *should* fix this.

But on the other hand, I have POS printers here that seem not to send
XON/XOFF for certain commands, so I have the same problem, too.

Kind regards

Jan