Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read from /dev/ttyS0 via shell script 1

Status
Not open for further replies.

geebers

Technical User
May 29, 2009
20
US
Seems the only way that I can read ascii text coming accross /dev/ttyS0 is with a gui-type of serial console.

I need to do this with a shell script similiar to...

#!/bin/sh
cat /dev/ttyS0 > myFile.txt

...putting the output into a text file. Like I said, only gui programs seem to work. I guess I need to be able to initialize and/or open my serial port in my script. I've tried every setserial, stty options but nothing seems to work.
Thanks for any help.
 
Hello,

I had similar problems a long time ago on some flavour of Unix. Problem was that all kind of initialising like stty only helped as long as the execution of stty command ran, that is, new settings were gone immediately.

What helped finally was this: Create some process that will run on the serial port for some time, no matter how useless it seems at first glance, something like:
sleep 1000 < /dev/ttyS0 &

I never did it on Linux, but might be worth a try...
 
Worked like a charm! Thank you very very much! Please accept a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top