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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-02-2004, 10:42 PM
|
#1
|
|
Senior Member
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126
Rep:
|
Bash: read/write the serial interface?
I have a measurement device attached to the standard RS-232C interface of a PC.
Is it possible to use a bash script to send simple commands and read lines of data via that interface?
I also wonder if I could configure the interface (parity, etc...) from the bash script, or it should be done in a system config file (but which one?).
I use bash scripts extensively for other purposes, but this is something new to me.
Could you give me a hint to start me in the right direction?
Last edited by J_Szucs; 06-02-2004 at 10:44 PM.
|
|
|
|
06-02-2004, 11:15 PM
|
#2
|
|
Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,861
Rep: 
|
Perhaps your distro might have some/all of:
uucp
tip
rz/xz (zmodem programs)
kermit
I'm honestly not sure what would work best for you.
|
|
|
|
06-03-2004, 10:58 PM
|
#3
|
|
Senior Member
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126
Original Poster
Rep:
|
I had a glance at those programs, but I think some of those are modem-specific, others require that the same program be running at the other end of the connection.
A measuring instrument is neither a modem, nor is it running Linux (at least for the time being...).
It is something much simpler: you send it strings via the serial interface, and you read in its reply strings via the same interface.
By the first sight this seems to be so simple that there must be an easy solution in Linux, too.
Last edited by J_Szucs; 06-03-2004 at 10:59 PM.
|
|
|
|
06-04-2004, 01:48 AM
|
#4
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
I guess stty would allow you to set serial line parameters (speed, parity, ...), echo to send data and cat to receive data.
|
|
|
|
06-04-2004, 03:46 AM
|
#5
|
|
Senior Member
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126
Original Poster
Rep:
|
Well, actually I was wondering something like as a possible solution.
echo "commandstring" > /dev/ttyS0
will surely work, and send the command string to the measuring device via the serial port.
But how about receiving the input from the device?
Is this supposed to work?:
cat /dev/ttyS0
I am really in doubt...
Last edited by J_Szucs; 06-04-2004 at 03:48 AM.
|
|
|
|
06-04-2004, 02:44 PM
|
#6
|
|
LQ Newbie
Registered: Jun 2004
Distribution: gentoo
Posts: 12
Rep:
|
$ cat /dev/ttyS0
is supposed to work:
from http://www.technoir.nu/hplx/hplx-l/0208/msg00172.html -
I have now been able to eliminate this error source, by rereading the
setserial man page. ;-)
setserial /dev/ttyS0 baud_base 115200
and configure the LX to 9600 8n1
does the trick. I still don't know why, but now it works. I can verify
it with starting datacomm on the LX, setting it to 9600 8n1, terminal
type TTY and then doing a
echo hello > /dev/ttyS0
on the Linux box. Gives a "hello" on the LX.
In the other direction, if I do a
cat /dev/ttyS0
on the linux box, and enter hello[enter] on the LX, I get a hello on
the linux console.
|
|
|
|
06-04-2004, 02:51 PM
|
#7
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
This should work:
(stty raw; cat > data ) < /dev/ttyS0
|
|
|
|
06-04-2004, 03:09 PM
|
#8
|
|
LQ Newbie
Registered: Jun 2004
Distribution: gentoo
Posts: 12
Rep:
|
I am trying to do something similar, and I can write to my rs232 device like this:
$ echo hi >/dev/ttyS0
but when I try to read from it like this:
$ cat </dev/ttyS0
it hangs.
are you having any better luck? what settings are you using for setserial and stty?
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:29 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|