ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
im using a shell script to send a command to a device connected to the serial port by the command:
echo $cmd > /dev/ttyS0
and in the very next line im listening to the device`s response by :
cat < /dev/ttyS0 >temp
the problem is that due the time it takes to come to the "listen to the output" line after sending the command, some characters are lost...
please note that the "send command" and the "listen to the port" lines are right next to each other: no other command executes in between.
im using the `cat` command to listen to the port..while im listening, that command is active in the background..something like:
cat < /dev/ttyS0 > temp
so while this crook is listening to the port, if i try to send a command through the port like this:
echo $command > /dev/ttyS0
the echo command hangs, since that port is already locked by `cat ...`
in case u think of asking, al this `tamasha` (drama) has to be done using one serial port only..cant use any other port xcept /dev/ttyS0
I didn't make the test. Just reading bash man page and some thought. All you need is open the serial port as I/O, write something and read the answer, without close the port first. So, you have to use the shell to open this port in I/O mode, and the commands will inherit these files. To do this you have to open a sub-shell
Code:
( # the parenthesis opens a sub-shell
echo $cmd # content of cmd will be written to standard output
cat - >temp # cat will read standard input inherited from the sub-shell and write it to the temp file
) <>/dev/ttyS0 # Close the sub-shell and redirect its standard input and output to /dev/ttyS0
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.