Solved

redirecting standard in and standard out with serial port

Posted on 1998-08-12
1
258 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 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

733 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