LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-17-2004, 05:31 AM   #1
funkymunky
Member
 
Registered: Jun 2003
Location: Austin, Texas
Distribution: Fedora Core 8, 32-bit
Posts: 126

Rep: Reputation: 15
Unhappy 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



 
Old 06-17-2004, 06:09 AM   #2
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

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

Alex
 
Old 06-17-2004, 06:29 AM   #3
funkymunky
Member
 
Registered: Jun 2003
Location: Austin, Texas
Distribution: Fedora Core 8, 32-bit
Posts: 126

Original Poster
Rep: Reputation: 15
thats what i fear... but it HAS to be a shell script

does anyone else have any idea ??

 
Old 06-17-2004, 09:31 AM   #4
lone_nut
Member
 
Registered: Dec 2003
Location: Denmark
Distribution: Mandrake
Posts: 179

Rep: Reputation: 30
Are you makeing the device yourselvfs?, if so try to delay the sending.
 
Old 06-17-2004, 11:08 AM   #5
funkymunky
Member
 
Registered: Jun 2003
Location: Austin, Texas
Distribution: Fedora Core 8, 32-bit
Posts: 126

Original Poster
Rep: Reputation: 15
youre making me cry now..all im allowed to do is make changes to my shell script
 
Old 06-17-2004, 12:45 PM   #6
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Create coprocesses - two scripts

have one sending data, one listening.
 
Old 06-17-2004, 01:25 PM   #7
funkymunky
Member
 
Registered: Jun 2003
Location: Austin, Texas
Distribution: Fedora Core 8, 32-bit
Posts: 126

Original Poster
Rep: Reputation: 15
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

 
Old 06-17-2004, 10:31 PM   #8
funkymunky
Member
 
Registered: Jun 2003
Location: Austin, Texas
Distribution: Fedora Core 8, 32-bit
Posts: 126

Original Poster
Rep: Reputation: 15
what will happen if i change my port speed from 9600baud to something lower ? the device transmits at 9600baud..will i lose data?
 
Old 07-16-2004, 08:39 PM   #9
osvaldomarques
Member
 
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519

Rep: Reputation: 34
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script execution on halt linuxhippy Slackware 4 04-01-2005 07:09 PM
crond shell execution problems lm317t Linux - General 1 02-22-2005 09:46 AM
script execution Johng Programming 2 08-21-2004 04:58 PM
Speeding up the script, or the SQL Query? knickers Programming 1 04-13-2004 11:57 AM
auto execution script nimrod Linux - General 2 12-09-2002 03:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration