LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Speeding up Shell Script execution?? (http://www.linuxquestions.org/questions/programming-9/speeding-up-shell-script-execution-194511/)

funkymunky 06-17-2004 06:31 AM

Speeding up Shell Script execution??
 
hi!

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.

help!

thanx in anticipation

Mayank



:eek:

llama_meme 06-17-2004 07:09 AM

Unfortunately, you probably need to rewrite this in a more suitable language (e.g. C, possibly Python).

Alex

funkymunky 06-17-2004 07:29 AM

thats what i fear... but it HAS to be a shell script
:cry:
does anyone else have any idea ??

:(

lone_nut 06-17-2004 10:31 AM

Are you makeing the device yourselvfs?, if so try to delay the sending.

funkymunky 06-17-2004 12:08 PM

:cry: youre making me cry now..all im allowed to do is make changes to my shell script :cry:

jim mcnamara 06-17-2004 01:45 PM

Create coprocesses - two scripts

have one sending data, one listening.

funkymunky 06-17-2004 02:25 PM

is it really possible?

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

:cry:

funkymunky 06-17-2004 11:31 PM

what will happen if i change my port speed from 9600baud to something lower ? the device transmits at 9600baud..will i lose data?

osvaldomarques 07-16-2004 09:39 PM

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

That's all.


All times are GMT -5. The time now is 09:32 PM.