I was looking at the system.serial commands and it looks like there's no easy way to clear the entire buffer. This would be a very nice feature for a reset functionality where you want to void out all current data in the buffer.
So my question is if this is possible currently and is there an easy way to clear out the buffer. If it isn't a feature where could I make a feature request to possibly get this added in the future?
Just use .readBytes()
with a large number of bytes and a short timeout. Discard the result.
Something like this might work, untested:
with system.serial.port("COM1") as port:
port.serialPort.flushIOBuffers()
If it works, then it's because port.serialPort
gets you the underlying SerialPort from the serial library, which has a flushIOBuffers()
method.
No idea if this will accomplish what you're hoping, though.
1 Like
I think you'd have to throw in something like this to get at the private inner field:
from org.apache.commons.lang3.reflect import FieldUtils
with system.serial.port("COM1") as port:
jSerialPort = FieldUtils.readField(port, "serialPort", True)
jSerialPort.flushIOBuffers()
Disclaimer: Still untested