Reading the serial ports. Help

Reading the serial ports. Help

Post by Michael Moll » Wed, 17 May 1995 04:00:00



I'm in the process of porting a program from dos to linux.
Everything else is done, but I cannot figure out how to read the serial ports.

All the program has to do is log data supplied, via rs-232, by a dumb external
machine.  In dos I wrote a serial interrupt handler in assembly,  the rest in
C.  All the C code has been ported, but I don't have a clue as to how to go
about the serial routines.  All the docs I could find covered remote terminals
and console replacement.

The device that I have to read simply transmits a continuous stream of data.
It has no handshaking signals (hardware or software) - The redundancy is high.
If some data is not valid, you simply wait for it to be transmitted again.

 - Simple enough if you can get at the data.

Any ideas at all would be appreciated.

Michael

 
 
 

Reading the serial ports. Help

Post by Trent Piep » Thu, 18 May 1995 04:00:00




>I'm in the process of porting a program from dos to linux.
>Everything else is done, but I cannot figure out how to read the serial ports.

It's much easier than dos actually.  You can setup the serial port to the
correct paramerters (like 9600 baud, 8-1-N or whatever) with stty or with
terminal control calls in your program.  Then you just
fd=open("/dev/ttySX",O_RDWR);
read(buffer,fd,size);

and it will read size bytes from the serial port X into buffer.  You might want
to check out non-blocking IO, alarm(), and select() as well.

--
|Gazing up to the breeze of the heavens \ on a quest, meaning, reason  |
|came to be, how it begun \ all alone in the family of the sun         |
|curiosity teasing everyone \ on our home, third stone from the sun.   |


 
 
 

Reading the serial ports. Help

Post by Jon Barrilleau » Thu, 18 May 1995 04:00:00


Take a look in the man pages.  You can use open() to open the port,
ioctl() to configure it (man pages won't help much for this :)), read()
to read data from the port and write() to write data to it.

Hope this helps.

--jon

 
 
 

Reading the serial ports. Help

Post by Michael Moll » Thu, 18 May 1995 04:00:00




Quote:>Take a look in the man pages.  You can use open() to open the port,
>ioctl() to configure it (man pages won't help much for this :)), read()
>to read data from the port and write() to write data to it.

>Hope this helps.

>--jon

What I've done is this:
I've opened /dev/ttyS0 using open().
I've not used ioctl(), since the only relevant info I could get was from the
LPG, which suggests using the POSIX method - tcgetattr(), tcsetattr(), etc.
At this stage I do not care to write, and read() does not return anything.

It seems to me that the promblem lies with the setup of the tty line, whether
using ioctl() or the POSIX method.  If you've done any programming reading the
tty lines in "raw" format, an example would be appreciated.  The miniterm.c
example that came with the LPG was not particularly useful.  It sets up the
termios structure using some cryptic flags which I could not find documented
anywhere...

Any more ideas?  Where are all those comms gurus?

l8r

--Mike

 
 
 

1. (*Help*) How do you read data from serial port on Sun (*Help*)

Hi all,

I need to hook up a regular rs232 cable to the serial port on a Sun
SPARC Classic and then write a C/C++ program to read the information
coming in on that port.

Here are my questions:

1. What device should I specify? (/dev/ttya is not responding to tip)
2. Besides tip, is there another UNIX utility that can test a device
   to make sure data is comming on that serial line connection.
3. Are there any libraries or tools that give you an API to help
   you write the C/C++ program.

Thanks,
-Vafa


2. unix com

3. Help needed for reading serial port under SCO 3.2

4. 2.5.67 buffer layer error at fs/buffer.c:127

5. help - reading data from serial port

6. 2.5.44 loses mouse & keyboard when going into X

7. HELP: looking for unix scripts to read data from serial port

8. when being port scanned

9. Help reading the serial port

10. "Help needed : read special character from serial port"

11. Help needed : read special character from serial port

12. read and write from serials ports, HELP

13. Need help reading from serial port on Solaris x86