deathraylabs
Newbie
- Joined
- Jun 18, 2019
- Messages
- 3
Serial port noob here. I'm using my SDS100 as an excuse to learn some python and Raspberry Pi programming, which is fun, but I'm a little confused about the various read/write buffers. Specifically, is there a way to clear the scanner's internal serial buffer without simply reading all the data it contains?
My issue is that it seems as though the scanner has an internal stack of data that it sends to the serial buffer in chunks of approx 1000 bytes. If I flush the buffer on my end, the scanner just grabs the next chunk that was waiting to be send and sends it to the buffer. It will repeat this process until the scanner's internal buffer is empty. I can just use a `read_all` command to fully empty the buffer but it's time consuming and would prefer just sending a command if available (I didn't find it in the SDS100 serial command spec sheet).
If you need more context, here's an example sequence of events I've seen:
My issue is that it seems as though the scanner has an internal stack of data that it sends to the serial buffer in chunks of approx 1000 bytes. If I flush the buffer on my end, the scanner just grabs the next chunk that was waiting to be send and sends it to the buffer. It will repeat this process until the scanner's internal buffer is empty. I can just use a `read_all` command to fully empty the buffer but it's time consuming and would prefer just sending a command if available (I didn't find it in the SDS100 serial command spec sheet).
If you need more context, here's an example sequence of events I've seen:
- I send a `PSI,1000` command to the scanner and the scanner starts pushing scanner information to the buffer every second.
- Lets say 8 seconds elapses and I haven't read any info on the buffer or sent any commands.
- I now send the command `PSI,0`, which tells the scanner to stop pushing scanner information to the buffer.
- When I use the pyserial command `in_waiting` I see something like 941 bytes waiting to be read.
- I read the the 941 bytes.
- `in_waiting` now says I have 1010 bytes waiting in the buffer.
- Flushing the buffer gets rid of those 1010 bytes.
- `in_waiting` shows 964 bytes are now waiting in the buffer for me.
- The process continues until all the xml "pushed" by the PSI command has been read, even though the PSI command is no longer actively pushing scanner information.