Solved

redirecting standard in and standard out with serial port

Posted on 1998-08-12
1
239 Views
Last Modified: 2010-04-20
I want to be able to send two bytes to /dev/cua1 and then read back 16 bytes. I want to do this from the command line or a shell script.

I want to send a capital "O" followed by a carriage return to /dev/cua1 at a baud rate of 300bps, 8 data bits, no parity, and 2 stop bits.

I then want to read back 16 bytes from /dev/cua1 at 300bps, 7 data bits, even parity, and 2 stop bits.  

Note: the different data bits and parity between writing and reading.

I'm running Redhat linux 5.0.

Thanks.  (Sorry for the lack of points, that's all I have)
0
Comment
Question by:mag062397
1 Comment
 
LVL 2

Accepted Solution

by:
JYoungman earned 50 total points
ID: 1637786
First, turn off normal CRLF translations etc., and set the outgoing settings:-
   stty 300 cs8 -parenb cstopb raw -opost< /dev/cua1

Then send the 2 bytes to /dev/cua1:-
   echo -n "O\r" > /dev/cua1
(the -n suppresses the automatic LF that echo usually produces).

Change the settings for the port:-
   stty 300 cs7  parenb -parodd cstopb raw -opost </dev/cua1

Then read in 16 bytes
   dd count=16 bs=1 </dev/cua1 >foo

This reads them into a file (you can read them into a shell variable using the $() construct if it's just text)


If the response from the remote end is instantaneous, there is a problem that the response might come back before the serial settings have been changed.  There's also an output race condition.  This is the point of the business with "cread", which may or may not work.  If not, we may have to switch to using C.

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now