Solved

redirecting standard in and standard out with serial port

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS - HAProxy- KeepAlived 5 43
su - oracle could not open session 6 78
how to rebuild XFS volume from LV 19 65
linux 13 50
How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

810 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