I tried something similar for my project, but had to go with a C program to do the reading (per Dave, I believe).
I haven't done it yet, but the reason was as stated below: the shell script is buffered and so it requires a <cr> to read the last line sent.
Since (in my project) that last line is the EOF, I _really_ needed it :)
 
I just had a thought, don't know if it would work... Could one put a timer on the loop so that if nothing is received within a certain amount of time, you could "push" a <cr> into the /dev/ttyS2? I thought I would post it because I can't even get to testing it until later today and perhaps someone has already tried...
(In my case, I can wait 3 sec and generate my own EOF if I had to)
 
-jim
 
-----Original Message-----
From: gumstix-users-bounces@lists.sourceforge.net [mailto:gumstix-users-bounces@lists.sourceforge.net]On Behalf Of a b
Sent: Wednesday, January 24, 2007 11:47 PM
To: gumstix-users@lists.sourceforge.net
Subject: [Gumstix-users] Reading tty using a simple shell script

--- I browsed the forums and google endlessly to find a simple way 
    to read serial data a tty.  I found a way and am thinking it may save some
    other poor soul hours of searching :)

--- First I set ttyS2 (2nd serial on the stuart board) to the following...
    (you can review your settings with 'stty -a -F /dev/ttyS2')

   speed 115200 baud; rows 0; columns 0;
   intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
   eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
   lnext = ^V; flush = ^O; min = 1; time = 0;
   -parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
   -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -ixon -ixoff
   -iuclc -ixany -imaxbel
   opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
   isig -icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
   echoctl echoke

--- To read the data I created the following sh script...
  #!/bin/sh
  while [ 1 == 1 ]; do
    read < /dev/ttyS2 a
    echo $a
  done

---  When the above script is run, it will loop infinitely, the while [ 1 == 1 ]; do..
the 'read < /dev/ttyS2 a'  actually waits until it receives a <cr> or \n and then it sets the read to var 'a'.  the echo simply echos the data to your screen.

Hope this helps!
-don




Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.