[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

redirecting standard in and standard out with serial port

Posted on 1998-08-12
1
Medium Priority
?
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Fine Tune your automatic Updates for Ubuntu / Debian
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

650 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