Using COM ports with read/write OR streams with fread etc?

Using COM ports with read/write OR streams with fread etc?

Post by Oskar Sande » Wed, 07 Oct 1998 04:00:00

I'm using a linux configured PC to read data from 4 comports. The
application i supposed to read datapackets of ca 100bytes arriving in a
rate of about 100Hz to each com port. Occationaly, controll & data
requst messages will be sent by the PC to the sources. My main task is
to do quite heavy computations on this data, so I want the
communications to be as effective as possible.

I've used the low level read/write commando. And select to give an
interrupt when sothing is available to read on a com port. This worked
fine for a 1Hz data rate, but when i cranked up the rate, it seems like
I loose caracters while I'm trying to write. I's the write command safe
to use, or will incoming data be thashed when i write?

Do I have to use buffering on the ports (i.e. vbuf and streams) or do I
just simply have to be more carefull when writing, so I'm not thrashing
an incoming message (Using select call to se if it is possible to write
at a given instant)

Best Regards

Oskar Sander


Using COM ports with read/write OR streams with fread etc?

Post by A.van.Kesse » Wed, 07 Oct 1998 04:00:00

Check the serial line settings/handshake, etc.
Also check the machine load. Under heavy CPU load (assuming correct handshake)
there would not be lost characters: the system would just throttle down to
lower serial throughput.
What happens next depends on how the peripherals react to beeing unable to
send the data they want: they could drop bytes, packets, overrun ring buffers,
or whatever.

Happy hacking,

Adriaan van Kessel.
Ingres DBA, C/Unix hacker

(remove NotThere. from the address in the header)
*** Nederlandstalige zachtwaar is een pijn in de aars ***


1. Question on writing c program implement cp function using UNIX system calls - read, write, etc.

I need to write a c program that will perform like the cp command in UNIX
and copy one file to another. I need to use the UNIX system calls read(),
write(), open(), close(). I know how to open the source file for read access
and destination file for write access with open(), but I am unsure of how to
use read() and write().

I know read takes my file descriptor (fd) of the source file I opened as its
1st arguement. For the second, I need to put those bytes in some sort of
buffer right? Could I just write them directly to the destination file
instead of storing into a buffer? Well if I have to make a buffer for input
I read in I do this:

c = (char *) calloc(100, sizeof(char));

Is that right? If I do this will it work for all files whether they are
binary or ascii files?

The 3rd arg of read() takes in how many  bytes to read, how do I tell it to
read in the entire source file?

So for read, this is what I have so far: read(fd, c, ????) where fd is my
source file descriptor and c as define above.

As for write, I have: write(fd2, ???, ???) where fd2 is the file descriptor
of my destination file. How do I specify it to write what I read from the
input source file and write all of those bytes inputted? Thanks for any

2. /dev/volctl: no such device or address

3. Need help writing C program using UNIX system calls (read, write, etc) that copies files

4. Problem with the ADAPTIC 1542B with 2.5, X86

5. iosched: effect of streaming read on streaming write

6. Some really stupid questions

7. iosched: impact of streaming write on streaming read

8. Seperate cgi-bin for virtual domain and Apache 1.0.3

9. How to read/write com ports on PC?

10. polling a port addres for a clock pulse and reading and writing data to RS422 port

11. reading port x -> writing port y

12. Does fread() block on piped streams?

13. Sockets: write() writes OK, yet read() reads garbage...?