LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-12-2010, 05:54 PM   #1
mmof
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Rep: Reputation: 0
Bash Serial port Script wont hang up


My linux computer runs ubuntu 10.04
I have it hooked up to a device, and the device manual says:

Device Specs:
Baud Rate: 9600
Data Bits: 7
Parity: odd
Stop Bits: 1
Flow control: None

Here is my script:

#!/bin/bash
stty -F /dev/ttyS0 9600 cs7 parenb parodd -cstopb clocal -crtscts -ixon -ixoff
echo "Enter file name [*.txt]:"
read "mytestfile"
echo "200 201" > /dev/ttyS0
cat /dev/ttyS0 > $mytestfile


PROBLEM 1:

The file gets created and most of the data gets saved to it, but the terminal never goes back to the ~ (home directory?) when finished. I can type whatever I want but it wont go anywhere or do anything even when I press enter. I have to click the X to close it and then the prompt comes up saying something like "are you sure you want to close terminal and kill all processes".
How do I fix it?
Reset does not work nor does the "stty sane" command that I read would force it to reset.

PROBLEM 2:

See the 00/01 character in front of 200 and 201, those are <SOH> commands and in the file they are supposed to show up, sometimes they do, sometimes they don't. But there is always supposed to be an <ETX> after each one, and with the way its written now, no <ETX> shows up,
<ETX> is 00/03 i think.

Here is what the output is supposed to look like:

<SOH>
200
BLAH BLAH BLAH DATA DATA
DATA DATA DATA DATA
<ETX>
<SOH>
201
BLAH BLAH BLAH DATA DATA
DATA DATA DATA DATA
<ETX>

yet the first SOH doesn't show up half the time and none of the ETX show up.
If anyone knows why, I would appreciate the push in right direction.
 
Old 10-12-2010, 06:47 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,961

Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
Welcome to LinuxQuestions!

Might be homework related?
Looks like you are trying to implement some type of file transfer. Some more information about this device and what you are actually trying to do is required to help you.
BTW
SOH - Start Of Heading
STX - Start of Text
ETX - End of Text.
EOT - End of Transfer

So something like a SOH at start of transfer. STX at beginning and ETX at the end of each "line" of data. The 200 looks like number of lines of data sent but need further definition. So basically your program would need to read a number of bytes from the file and then send the STX, send data, ETX characters. You would loop until all bytes are read/transfered and then send the EOT character.

Have you tried CTRL-C to quit the program?
 
Old 10-12-2010, 07:22 PM   #3
mmof
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Original Poster
Rep: Reputation: 0
I appreciate the reply,
I am talking to a Veeder Root Tank monitor.

Link to pdf, of the serial manual
http://www.veeder.com/object/576013-635.html

The 200 is the actual command sent to the device.
And I'm new to linux and the only way I got it to talk was to send the soh character. In windows all I had to do was open hyperterminal configure baud rate parity etc. and hit connect, then all I had to press was "ctrl + a" then "200" minus the quotations.

And it would bring up the soh (ctrl + a) symbol then 200 (which is the command) then the data then etx(end of text as you pointed out)

I just tried the CTRL-C like you said, and when I type it in it does return me to the ~ directory, but how do I echo it so that the program does it by itself?
This sounds funny but, the "hello_world" program I did in the book I bought a few weeks ago went back to it by itself. (I'm a newb, I know)
Thanks again for your help, if you need anymore information on the device let me know.
 
Old 10-26-2010, 02:16 PM   #4
mmof
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Original Poster
Rep: Reputation: 0
I got it to work!!!!!
The problem was when this line : "cat /dev/ttyS0 > $mytestfile"
would get called, the script would run correctly but it would keep the serial port open, which is why i could never run a single command after wards.

So to fix this I did this:

#!/bin/bash
stty -F /dev/ttyS0 9600 cs7 parenb parodd -cstopb clocal -crtscts -ixon -ixoff
mytestfile=mmof.txt
cat /dev/ttyS0 >> $mytestfile

I have this script run in the background at boot up, and it continues to run the entire time the computer is on.

Then I just run the other script:

#!/bin/bash
stty -F /dev/ttyS0 9600 cs7 parenb parodd -cstopb clocal -crtscts -ixon -ixoff
echo "200 201" > /dev/ttyS0

This is the basic version, I have made a big amount of changes to it, to suit my needs for what the script must do at certain times.
But if anyone is having trouble with cat /dev/ttys0 > textfile.txt
The problem is more than likely when you cat the serial port, it never closes, so the simplest solution to this was to just make a script which always runs in the background. I hope this helps. I searched for so many hours/days/weeks for a solution and last night I thought of this and it worked, and it has been working ever since running ever hour updating the file. I hope this answers others problems with cat and serial port issues.
Thanks, mmof
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Creating a bash script with serial port input Elv13 Linux - Hardware 10 06-08-2010 08:01 AM
serial port is getting hang shariefbe Linux - Software 6 01-18-2010 04:22 AM
Bash Sleep vs crontab and bash serial port nutthick Programming 4 06-01-2006 03:42 AM
Palm wont sync on serial port sirius57 Linux - Hardware 4 01-20-2005 12:38 PM
Why can't I read in data from the serial port using a bash script? tjt Linux - Newbie 1 06-17-2004 01:21 AM


All times are GMT -5. The time now is 07:13 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration