?
Solved

redirecting standard in and standard out with serial port

Posted on 1998-08-12
1
Medium Priority
?
272 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 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

807 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