LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 10-21-2006, 05:34 PM   #1
seraph-seph
Member
 
Registered: Jul 2005
Location: /dev/ATX3
Distribution: Slackware 11(kernel 2.6.17.13), SuSE 10, Caldera, CentOS 4.3
Posts: 38

Rep: Reputation: 15
How to read serial port (/dev/ttyS0)


Hi everyone.


I'm having some troubles reading the serial port, I'm traying to communicate two machines (one with winxp and the other with slackware) when I set up the communication at 1200, 7, even parity and one(1) stop bits it works fine sending. The setup in linux is this

Code:
stty 1200 cs7 -parodd -cstopb < /dev/ttyS0
echo "testing" > /dev/ttyS0
I receive in a HyperTerminal (winXP) set up as 1200b, 7bits, parity even and one stop bit. testing

But when I try to read data using
Code:
cat /dev/ttyS0
And send data using an app in vbasic set up with the same parameters, it doesn't read anything, I figure out that as End of transmission is sending char 20 instead of char 13 and as requirement I can't change the way it transmits.

Does anybody knows how to read serial port using shell bash without waiting for the carriage return?


Thanks
Mario
 
Old 10-21-2006, 07:01 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
What if you try reading one byte at a time (e.g., while head -c 1 /dev/ttyS0; do : ;done)?
 
Old 10-21-2006, 08:45 PM   #3
seraph-seph
Member
 
Registered: Jul 2005
Location: /dev/ATX3
Distribution: Slackware 11(kernel 2.6.17.13), SuSE 10, Caldera, CentOS 4.3
Posts: 38

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by osor
(e.g., while head -c 1 /dev/ttyS0; do : ;done)?
Seems logic, let me see if I understood, "head" would be the variable to print?

Mario
 
Old 10-31-2006, 07:26 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by seraph-seph
Seems logic, let me see if I understood, "head" would be the variable to print?

Mario
Sorry it's been so long...

Did you already figure this out?

head is not the variable. head is a UNIX command that usually prints the first few lines of a file (i.e., the head of the file). As this is intended for textfiles and looks for newlines, you use the -c flag, which, AFAIK, will print a number of characters (or bytes) at a time, disregarding EOF, EOL, EOT, or whatever. For any normal file, it is useless to print the first character repeatedly, but a serial device is (I think) like a FIFO, so it should work. So the entire (bourne shell) sequence
Code:
while head -c 1 /dev/ttyS0
do
	: # a dummy command that always returns true
done
does what you think "cat /dev/ttyS0" would do... that is, print the serial output (to stdout) as it comes in.

If you want to read it in a script, you could do a number of things (i.e., use parentheses/braces around the entire thing and use redirection or backtick quotes, or make the command a simple executable file on whose output you could use redirection or backticks).
 
Old 11-01-2006, 06:55 AM   #5
seraph-seph
Member
 
Registered: Jul 2005
Location: /dev/ATX3
Distribution: Slackware 11(kernel 2.6.17.13), SuSE 10, Caldera, CentOS 4.3
Posts: 38

Original Poster
Rep: Reputation: 15
Hi again.

Yes, I figure it out, I tried this one but wasn't enough, what I did was to set control by hardware and keep reading it for a set time.

this is what I used.
Code:
stty 1200 ..... sane -echo -echok -icrnl -ixon -icanon -opost -onlcr time 3 min 0 < /dev/ttyS0
while [true]
do
     cat /dev/ttyS0
done
Where time and min where the cycle time to read the port.
 
  


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
writing to serial port, /dev/ttyS0 togunter Programming 2 06-08-2008 09:27 AM
How to read serial port (/dev/ttyS0) without end of transmission seraph-seph Programming 1 10-22-2006 01:03 AM
Serial Port HowTo (Cannot open /dev/ttyS0) chun-mee Linux - Hardware 2 07-14-2006 05:35 PM
Unable to communicate using serial port (COM1) /dev/ttys0 vinaybms Linux - Networking 1 03-11-2005 08:08 AM
Telnet into Cisco router via /dev/ttyS0 (aka COM1 serial port) naesyllek Linux - Networking 2 06-25-2003 05:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 06:44 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