LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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-02-2004, 10:42 PM   #1
J_Szucs
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: Reputation: 58
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.
 
Old 06-02-2004, 11:15 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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.
 
Old 06-03-2004, 10:58 PM   #3
J_Szucs
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: Reputation: 58
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.
 
Old 06-04-2004, 01:48 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,493

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
I guess stty would allow you to set serial line parameters (speed, parity, ...), echo to send data and cat to receive data.
 
Old 06-04-2004, 03:46 AM   #5
J_Szucs
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: Reputation: 58
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.
 
Old 06-04-2004, 02:44 PM   #6
philetus
LQ Newbie
 
Registered: Jun 2004
Distribution: gentoo
Posts: 12

Rep: Reputation: 0
$ 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.
 
Old 06-04-2004, 02:51 PM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,493

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
This should work:

(stty raw; cat > data ) < /dev/ttyS0
 
Old 06-04-2004, 03:09 PM   #8
philetus
LQ Newbie
 
Registered: Jun 2004
Distribution: gentoo
Posts: 12

Rep: Reputation: 0
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?
 
  


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
Mounted read-write Fat32 partition suddenly becomes read-only?? hohead Linux - General 8 04-05-2007 12:17 PM
Example share in smb.conf doesn't work - read/write vs read only kleptophobiac Linux - Networking 0 09-01-2004 07:14 PM
how do I change the filesystem from read-only to read-write? les_chow Linux - Newbie 5 05-26-2004 03:14 PM
Open office read only, K-write read/write mode lwtvh Linux - Newbie 1 07-19-2003 11:33 AM
Change from Read only to Read Write File System? justiceisblind Linux - Newbie 3 03-03-2002 07:23 PM


All times are GMT -5. The time now is 09:48 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration