SDS100/SDS200: PSI serial port command—how do I clear the scanner buffer after setting "PSI,0"

Status
Not open for further replies.

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:
  1. I send a `PSI,1000` command to the scanner and the scanner starts pushing scanner information to the buffer every second.
  2. Lets say 8 seconds elapses and I haven't read any info on the buffer or sent any commands.
  3. I now send the command `PSI,0`, which tells the scanner to stop pushing scanner information to the buffer.
  4. When I use the pyserial command `in_waiting` I see something like 941 bytes waiting to be read.
  5. I read the the 941 bytes.
  6. `in_waiting` now says I have 1010 bytes waiting in the buffer.
  7. Flushing the buffer gets rid of those 1010 bytes.
  8. `in_waiting` shows 964 bytes are now waiting in the buffer for me.
  9. 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.
Hope this makes sense, and thanks in advance for any help you can provide!
 

dougjgray

Member
Joined
Mar 8, 2003
Messages
535
Location
Englewood CO
I have not used the PSI command and I dont think there is any way to clear the buffers in the scanner other then reading the data. I have used in C# the GSI command to read the XML till it reads the end (</ScannerInfo>\r). I would think that would work for the PSI as well, if you read all the data, then you have the scanner buffer is empty. With PSI the scanner sends every second or what ever interval you need. if it helps here is the C# code. I use a timer in the program set to 1 sec, to read every second. I don't know whether Python has a ReadTo Command

serialPort1.WriteLine("GSI\r");
Data = serialPort1.ReadTo("</ScannerInfo>\r");
Data += "</ScannerInfo>\r";
Data = Data.Substring(11);
 
Last edited:

deathraylabs

Newbie
Joined
Jun 18, 2019
Messages
3
Thanks for the response dougjgray. It's heartening to see that we both approached reading the GSI response in a similar manner. Your code is how I was originally getting scanner information before trying out the PSI mode, albeit in in C# instead of python.

Do you have any idea why one would choose PSI mode over GSI mode or vice versa?

I chose PSI mode mainly just to figure out how to work with data waiting at the buffer, not because I had a really good reason choose it over GSI mode. I'm guessing when I progress a little further and am sending key commands it will probably get confusing having the scanner send push updates instead of pulling them with GSI. I saw somewhere in another thread that the PSI mode is useful when the scanner is processing a command with a status bar, in that you might be blocked from it processing a GSI command to update screen while PSI will keep sending screen data regardless.
 

dougjgray

Member
Joined
Mar 8, 2003
Messages
535
Location
Englewood CO
It did not see a need for the PSI, but if your program can process the data and be ready to recieve when the data comes from the scanner it would probably work. I suppose if your program gets behind you could adjust the the interval or read all the data available and parse some how excluding any data beyond what you need. But I wrote my program a few years ago for my 436hp mostly to emulate the Analyze data(Activity Log, Current Activity, LCN monitor) that was on my HomePatrol1 with the extreme upgrade. The Functions are on 436 but where not implemented, But as far as display the scanner screen info The GSI command worked ok so I went that way to display the Screen Info :). My experience with using the GSI on serial, I did not have any trouble sending key presses, but only implemented the 3 keys (SYSTEM,DEPT,CHANNEL). I does work for my SDS200 the display looks like a 436 :)
 

dougjgray

Member
Joined
Mar 8, 2003
Messages
535
Location
Englewood CO
I was thinking about the PSI command and since it is XML data maybe it would be a good way to send the data to a web site, since a command would not need to be sent, it would be sent at an interval. I am not good at website programming but might be interesting to experiment with sometime
 
Status
Not open for further replies.
Top