[Rxtx] read() not blocking?
Knute Johnson
knute at frazmtn.com
Sun Sep 24 13:26:19 MDT 2006
So I've redone my tests and specifically set the receive timeout and
receive threshold states.
receiveTimeoutDisabled() and receiveThresholdDisabled()
import java.io.*;
import java.text.*;
import java.util.*;
import gnu.io.*;
//import javax.comm.*;
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);
// both receive timeout and receive threshold disabled
sp.disableReceiveTimeout();
sp.disableReceiveThreshold();
System.out.println("isReceiveThresholdEnabled: " +
sp.isReceiveThresholdEnabled());
System.out.println("isReceiveTimeoutEnabled: " +
sp.isReceiveTimeoutEnabled());
InputStream is = sp.getInputStream();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
System.out.println("Started "+sdf.format(new Date()));
while (true) {
int n = is.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
isReceiveThresholdEnabled: false
isReceiveTimeoutEnabled: false
Started 12:06:48
12:06:48 -1
12:06:48 -1
12:06:48 -1
12:06:48 -1
12:06:48 -1
12:06:48 -1
12:06:48 -1
12:06:48 -1
12:06:48 -1
12:06:48 -1
12:06:48 -1
12:06:48 -1
Note that it returns very quickly from the read, many times per
second. This should block yes?
Next is:
enableReceiveTimeout(Integer.MAX_VALUE) disableReceiveThreshold()
import java.io.*;
import java.text.*;
import java.util.*;
import gnu.io.*;
//import javax.comm.*;
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);
// both receive timeout and receive threshold disabled
sp.enableReceiveTimeout(Integer.MAX_VALUE);
sp.disableReceiveThreshold();
System.out.println("isReceiveThresholdEnabled: " +
sp.isReceiveThresholdEnabled());
System.out.println("isReceiveTimeoutEnabled: " +
sp.isReceiveTimeoutEnabled());
InputStream is = sp.getInputStream();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
System.out.println("Started "+sdf.format(new Date()));
while (true) {
int n = is.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
isReceiveThresholdEnabled: false
isReceiveTimeoutEnabled: true
Started 12:09:11
12:09:51 -1
12:10:31 -1
12:11:11 -1
12:11:51 -1
12:12:32 -1
12:13:12 -1
Note the approximately 40 second timeout when Integer.MAX_VALUE
should yield about 562 hours.
I did just find something interesting, a timeout setting of 65535
gave a 1:26 timeout. I'm trying 3,600,000 now to see if it will be
close to an hour.
Any suggestions of what to try next would be great.
Thanks,
--
Knute Johnson
Molon Labe...
More information about the Rxtx
mailing list