Redirecting Serial port input to a file

Redirecting Serial port input to a file

Post by John C Bah » Fri, 16 Feb 2001 03:37:48



Hi,

I am trying to test serial throughput in Linux.  I have two machines
connected with a null modem serial cable and have successfully tested
communication via minicom.  (FWIW: Source machine is a i686 running
Redhat 7.0 and the target machine is an ARM running an embedded version
of Royal Linux)

I have read the Advanced Bash Scripting HOWTO's section on I/O
Redirection and
I am sending an ASCII text file (100 lines with the numbers 1 through
100 on their respective line) from the source computer like so:
cat sent.txt > /dev/ttyS0

I am attempting, from bash, to redirect the serial port data coming into
the target to a text file.  I have tried all of the following on the
target:

1) Take standard input from a file and direct standard input back to a
file:
    exec < /dev/ttyS0 > received.txt       (This causes the lines in the
file to be "executed" as commands, a blank received.txt to be received,
and my session logs out.)

2)  cat /dev/ttyS0 > received.txt             (This causes 3 or 4 lines
to be placed in received.txt : blank, some number, some greater number
and then the file is closed and I get a prompt back.)

3)  Run, from within a shell script:
    exec cat /dev/ttyS0 > received.txt    (This has the same effect as
case 2 above be the script exits.)

You can't, of course, just do a /dev/ttyS0 > received.txt.

I am running at a mere 9600 baud.  Could I be seeing receive buffer full
overruns?  Why would that cause case 2 and 3 to exit from their
environment?

"exec" seems to be what I need since without it, the command completes.
"exec" seems to cause the statement to keep redirecting the input.

I know I could write two little programs to do this but I thought since
redirection is so powerful...

This is all slightly complicated by the fact that sometime I can't break
out of a running task, and have to reboot the target, thus flushing my
RAM disk.  :-(

Has anyone done this kind of thing before?

Thanks,
John Bahr

 
 
 

Redirecting Serial port input to a file

Post by The Spoo » Mon, 19 Feb 2001 09:09:35


John C Bahr wrote ...
-- Cut --
Quote:>I have read the Advanced Bash Scripting HOWTO's section on I/O
>Redirection and
>I am sending an ASCII text file (100 lines with the numbers 1 through
>100 on their respective line) from the source computer like so:
>cat sent.txt > /dev/ttyS0

>I am attempting, from bash, to redirect the serial port data coming into
>the target to a text file.
-- Cut --

>I am running at a mere 9600 baud.  Could I be seeing receive buffer full
>overruns?

-- Cut --

You may have trouble with line disciplines (an integral part of ports that
may be used for terminals, like serial ports).

To disable the line disciplines, you should use stty (but be careful to
embed it in a subshell, as changes done to a serial line is lost after the
line has been closed).

The following might work:

    (stty raw; cat > received.txt) < /dev/ttyS0

Beware that cat will never end unless the port is closed by hardware
signals, as there is no interpretation of control characters in this setup
(Ctrl-D as end-of-file is normally caught by the line discipline and sent to
the process as an (inherently out-of-band) signal, but in this setup, the
line discipline is effectively disabled).

I hope this can get you somewhere.

  /TRY

PS: This will *not* work:

    stty raw < /dev/ttyS0; cat /dev/ttyS0 > received.txt

as /dev/ttyS0 is closed after the stty-command (with changes lost) and
reopened by the cat-command (with the original settings).

 
 
 

1. Redirecting input to a file - echo the input to screen/file?

Is it possible to have redirected input to a file also echoed to the
screen, or to a file?  For example, if I do something like the following:

$ ./program < input.txt > output.txt 2>&1

The output file shows everything coming out of the program (stdout and
stderr), but doesn't display the input.txt.

I tried adding 0>&1, but no-go (input hosed).

I can also cut and paste the input.txt file right in the shell, but it
doesn't show up for some reason in the shell (Redhat8.0).  Not sure what's
going on, any help appreciated.

2. HOWTO: r/w JFS filesystem on diskette

3. Redirecting input and output to serial port

4. DOSEMU updates

5. serial console - lilo serial= no serial port input

6. Any large solstice users out there?

7. Dumping Serial-Port-Input into a File

8. freesWan Ipsec Installation

9. How do I capture serial tty port input into a running log file?

10. Redirecting two input files to diff..

11. Redirecting Standard Input *TO* a file...

12. How to redirect input to files given as arguments?

13. Redirect a file to a running program as input?