23 January 2008

Serial Port and flow control with javax.comm

Sun doesn't provide a javax.comm implementation for Windows and they suggest to use a freely available implementation of their API called RxTx.

But I was having trouble getting the RTS/CTS hardware flow control going, like someone else.
It seems like some CTS events are missed.

At the end I succeeded by adding a wait loop for the CTS to go high before writing each character:

import gnu.io.*;
private SerialPort sPort;

private void osWrite( int val ) throws IOException
{
while( !sPort.isCTS() );

os.write( val );
os.flush();
}


One would expect this to happen in the background, but it doesn't with this particular implementation of javax.comm.

See also: http://en.wikibooks.org/wiki/Serial_Programming:Serial_Java#JavaComm

No comments:

Post a Comment