title: Serial communication with minimal delay
body: <p>I have a computer which is connected with external devices via serial communication (i.e. RS-232/RS-422 of physical or emulated serial ports). They communicate with each other by frequent data exchange (30Hz) but with only small data packet (less than 16 bytes for each packet).</p>
  
  <p>The most critical requirement of the communication is low latency or delay between transmitting and receiving.</p>
  
  <p>The data exchange pattern is handshake-like. One host device initiates communication and keeps sending notification on a client device. A client device needs to reply every notification from the host device as quick as possible (this is exactly where the low latency needs to be achieved). The data packets of notifications and replies are well defined; namely the data length is known. 
  And basically data loss is not allowed.</p>
  
  <p>I have used following common Win API functions to do the I/O read/write in a synchronous manner:
  CreateFile, ReadFile, WriteFile</p>
  
  <p>A client device uses ReadFile to read data from a host device. Once the client reads the complete data packet whose length is known, it uses WriteFile to reply the host device with according data packet. The reads and writes are always sequential without concurrency.</p>
  
  <p>Somehow the communication is not fast enough. Namely the time duration between data sending and receiving takes too long. I guess that it could be a problem with serial port buffering or interrupts.</p>
  
  <p>Here I summarize some possible actions to improve the delay. 
  Please give me some suggestions and corrections :)</p>
  
  <ol>
  <li>call CreateFile with FILE_FLAG_NO_BUFFERING flag? I am not sure if this flag is relevant in this context.</li>
  <li>call FlushFileBuffers after each WriteFile? or any action which can notify/interrupt serial port to immediately transmit data? </li>
  <li>set higher priority for thread and process which handling serial communication</li>
  <li>set latency timer or transfer size for emulated devices (with their driver). But how about the physical serial port? </li>
  <li>any equivalent stuff on Windows like setserial/low_latency under Linux?</li>
  <li>disable FIFO?</li>
  </ol>
  
  <p>thanks in advance!</p>