-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flush not working #1806
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week no further activity occurs. Feel free continue the discussion or ask for a |
V7.1.5 I can confirm. On Windows - flush callback is called but the buffers are never flushed. As a test, I am connected to a serial device that sends a packet every second. const SerialPort = require('serialport')
const Readline = require('@serialport/parser-readline')
const port = new SerialPort(process.argv[2], {
baudRate: 57600,
autoOpen: true,
rtscts: true
})
port.on('open', () => {
console.log("port opened");
port.flush((error) => {
console.log("port flushed")
const parser = port.pipe(new Readline({ delimiter: '\r' }))
parser.on('data', line => {
console.log(line)
})
})
}); Upon launching (passing the serial port name as first parameter), the code above prints all the packed that have been received since the last launch notwithstanding the flush. |
What behavior are you expecting? |
Parsers and streams have their own buffers which are not flushed by this command. It only flushes the os level buffers. |
The behaviour I am expecting Is to only see the data sent after the flush. But, if this is the case, should I flush the stream as well? |
How do you know when the data was sent? Open => flush => read might not miss any data, no data is buffered when the port is closed. |
The device I am using outputs one line per second to the serial. It is an USB device based on a FTDI chip. Just starting the above code should only print new data, one per second - it prints about a dozen of lines straight away. If I kill the process, wait 5 seconds, relaunch it - it prints 5 lines immediately, then one line every second. If I understand what you are saying, the device itself, and not windows, could be the one doing the buffering - but then I would get exactly the same behaviour on Linux |
Maybe, it might be paying attention to the line state when the port is closed and they’re might be different behavior between systems. Can you tell me more about the device? |
This is the device. I am implementing sl-can for a project As an additional note, (may help with troubleshooting) port.on('open', () => {
const old = port.read(65536);
if (old!=null) {
debug("Discarded", old.length, "bytes")
}
}); doesn't work either - immediately after an open port.read returns null, and later my "data" event is flooded with stale packets. As a note, my device requires rtscts - which may be broken on windows. |
Hi, Not sure how it plays out, but it looks like on startup port.flush does not see any data because there is no data to see (buffering is done by the device), so this is not an issue with port.flush in the first place |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week no further activity occurs. Feel free continue the discussion or ask for a |
Flush doesn't clear the buffer?
Code to Reproduce the Issue
Versions, Operating System and Hardware
The text was updated successfully, but these errors were encountered: