how best to read one line of text from ttyS0

how best to read one line of text from ttyS0

Post by John Jacob » Thu, 06 Apr 2000 04:00:00



Hi,

I have a piece of hardware hooked up to ttyS0 which outputs a line of data
(in ascii) when it receives any character.

Here's part of my current bash script:

echo a > /dev/ttyS0            # Start the device up and have it output its
line
read LINE1 < /dev/ttyS0     # Read the line of data into a variable

LINE1 contains the the line of data the hardware spits out. Simple. This
script fires once per minute and ran for 35 days without a problem. What
happened after day 35?  COMPLETE SYSTEM FAILURE, requiring a cold boot. How?

The piece of hardware failed and did not send back any information. Cron
kept launching the script every minute, and after a couple of hours the
system resources were exausted.

#1. How do I add some error checking or timeouts to this?

or

#2. Is there a much slicker way of doing this?

Thanks!

 
 
 

how best to read one line of text from ttyS0

Post by Barry Margoli » Thu, 06 Apr 2000 04:00:00




>The piece of hardware failed and did not send back any information. Cron
>kept launching the script every minute, and after a couple of hours the
>system resources were exausted.

>#1. How do I add some error checking or timeouts to this?

>or

>#2. Is there a much slicker way of doing this?

Instead of launching a separate cron job every minute, why not have a
single background process in an endless loop, with a "sleep 60" at the end
of each iteration?

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

how best to read one line of text from ttyS0

Post by John Jacob » Thu, 06 Apr 2000 04:00:00


Quote:> Instead of launching a separate cron job every minute, why not have a
> single background process in an endless loop, with a "sleep 60" at the end
> of each iteration?

Excellent, I'll do that... that makes much more sense. Now, the process
could still stall on the error condition.

To detect failure, would it be too cheesy to have this process create a text
file before starting, then delete it before the "sleep 60", and have ANOTHER
process looking for this text file* around more than a minute, or is
there something with variables that would make more sense?

 
 
 

how best to read one line of text from ttyS0

Post by Barry Margoli » Thu, 06 Apr 2000 04:00:00




>> Instead of launching a separate cron job every minute, why not have a
>> single background process in an endless loop, with a "sleep 60" at the end
>> of each iteration?

>Excellent, I'll do that... that makes much more sense. Now, the process
>could still stall on the error condition.

True, but it won't kill your entire system due to creation of hundreds of
processes.

Quote:>To detect failure, would it be too cheesy to have this process create a text
>file before starting, then delete it before the "sleep 60", and have ANOTHER
>process looking for this text file* around more than a minute, or is
>there something with variables that would make more sense?

Rather than creating and deleting it, it could use "touch" to update the
modification time of the file.  The other process could check whether the
modification time is more than a minute old.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

1. How to Reliably read two lines of text from ttyS0?

Hi, I have a hardware device hooked up to the serial port that measures the
temperature. To get a reading, you send any character to the port, then it
starts reporting the temp like this (if you look in Minicom or something):

T1  15.2
T2  14.5
H1  etc
H2  etc

I am starting the reading by echoing a character to ttyS0, then I do two
reads to get T1 and T2:

echo a > /dev/ttyS0        #start the reading by sending any char
read T1 < /dev/ttyS0      #grab T1
read T2 < /dev/ttyS0      #grab T2

Is there a better way to do this? (I'm using bash.)

The problems I'm having is I have to put "sleeps" between the two readings
otherwise I either get occasional garbage, or half of one line and half the
other, or T2 reads instead of T1, or T1 is read twice in a row.

Even with a "sleep 1" between the two reads, it still is not reliable. About
1 in 20 reads is wrong.

I feel I'm missing some super-easy way to read two lines of text from ttyS0
. . .

Thanks!

John

2. Replacing Gnome with KDE?

3. How to read text line-by-line in shell script?

4. How to build the floppy of LRP (Linux Router Project)?

5. read from stdin while reading line by line a file

6. SSH in Solaris

7. "lp" prints only the first line of any text file.

8. Socket Error in lbxproxy on Solaris

9. catching first words of a multi-line text

10. Run one command for each line of a text file

11. getting the first X chars of a text line using sed.exe

12. Extraction of text in one line

13. Removing the first line of a text file