Serial port latency

From: Geir Thomassen (geirt@powertech.no)
Date: Thu Mar 22 2001 - 13:21:28 EST


Hi.

My program controls a device (a programmer for microcontrollers) via the
serial port. The program sits in a tight loop, writing a few (typical 6)
bytes to the port, and waits for a few (typ. two) bytes to be returned from
the programmer.

The program works, but it is very slow. I use an oscilloscope to monitor the
serial lines, and notices that there is a large delay between the returned
data, and the next new command. I really don't know if the delay is on the
sending or the receiving side (or both).

This is what the program does:

     fd=open("/dev/ttyS0",O_NOCTTY | O_RDWR);

     tcsetattr(fd,TCSANOW, &tio); /* setting baud, parity, raw mode, etc */

     while() {
             write( 6 bytes); /* send command */
             read( 2 bytes); /* wait for reply */
     }

The device on the serial port responds in typ. 10 ms, but the software uses
over 500ms to get the reply and send the next command. Why is this happening ?
I have a feeling that there is something obvious I am missing (like line
buffering, but that's a stdio (libc) thing, isn't it ?).

BTW, I am running a 2.2 kernel ....

Geir, geirt@powertech.no
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Mar 23 2001 - 21:00:18 EST