[Rxtx] read() not blocking?
Knute Johnson
knute at frazmtn.com
Sat Sep 23 19:47:00 MDT 2006
Here is my test program and the output. I've tried it on my Dell 380
desktop and my old Dell laptop and the results are the same.
import java.io.*;
import java.text.*;
import java.util.*;
import gnu.io.*;
public class test {
public static void main(String[] args) throws Exception {
CommPortIdentifier cpi =
CommPortIdentifier.getPortIdentifier("COM1");
SerialPort sp = (SerialPort)cpi.open("test",2500);
// set serial port parameters
sp.setSerialPortParams(9600,SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
sp.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
sp.enableReceiveTimeout(Integer.MAX_VALUE);
InputStream is = sp.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
System.out.println("Started "+sdf.format(new Date()));
while (true) {
int n = bis.read();
System.out.println(sdf.format(new Date())+" "+n);
}
}
}
C:\com\knutejohnson\redrock\race>java test
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
Started 18:40:11
18:40:51 -1
18:41:31 -1
18:42:11 -1
18:42:51 -1
18:43:31 -1
Thanks,
--
Knute Johnson
Molon Labe...
More information about the Rxtx
mailing list