When I set the output buffer size to either 0 or 1 (or even 10), it does not seem to have effect.
If I transmit on a low baudrate, and I send a lot of text by writing 1 byte at the time to the OutputStream and calling flush() after each byte written. If I then stop writing, the serial data lingers on for quite a bit (I expect at least 256 chars, but probably more).
Alternatively, a way to reset/clear the output buffer(s) (on all levels, java/jni/os/hardware) would also solve above issue.
Code used to initialize the serial port:
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(portName);
SerialPort port = portId.open("Me", 5000);
port.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
//port.setFlowControlMode(gnu.io.SerialPort.FLOWCONTROL_RTSCTS_IN | gnu.io.SerialPort.FLOWCONTROL_RTSCTS_OUT);
port.setOutputBufferSize(1);
port.setInputBufferSize(1);
port.enableReceiveTimeout(receiveTimeOutMillis);
port.notifyOnDataAvailable(true);
//port.notifyOnOutputEmpty(true); // turning this on seems to disable other events
port.notifyOnCTS(true);
port.notifyOnDSR(true);
port.setRTS(false);
port.addEventListener(eventHandler);
Below snippet is what I use to write the data:
byte data = ....;
port.getOutputStream().write(data);
port.getOutputStream().flush();
When I set the output buffer size to either 0 or 1 (or even 10), it does not seem to have effect.
If I transmit on a low baudrate, and I send a lot of text by writing 1 byte at the time to the OutputStream and calling
flush()
after each byte written. If I then stop writing, the serial data lingers on for quite a bit (I expect at least 256 chars, but probably more).Alternatively, a way to reset/clear the output buffer(s) (on all levels, java/jni/os/hardware) would also solve above issue.
Code used to initialize the serial port:
Below snippet is what I use to write the data: