I communicate with a unit to control a satellite antenna via a serial connection.

Opening a connection with the serial device:

import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

portIdentifier = CommPortIdentifier.getPortIdentifier(device);
serialPort = (SerialPort) portIdentifier.open(name, 
serialPort.setSerialPortParams(baudrate, databits, stopbits, parity);
serialPort.setFlowControlMode(flowMode);

bufferedReader = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
outputStream = serialPort.getOutputStream();

If the unit is becomes unavailable, I have to clear the stream before being able to send new commands, once the device is up again. But this clear method on the input/output stream blocks if the device is down. Also closing the streams, or closing the SerialDevice blocks.

Is there a way to close/clear these streams or SerialDevice without blocking?

bufferedRead.close(); // blocks until device is up again
outputStream.close(); // blocks until device is up again
serialPort.close(); // blocks until device is up again
Edit
Report