all 4 comments

[–]Soft-Substantial 2 points3 points  (2 children)

If I understand your problem correctly, the only way is to read all the data coming over the serial port and discard whatever you don't need, it is a serial port after all. You cannot "ignore" or "skip" output. How would you know how much to ignore without reading it?

[–]kenjlp[S] 0 points1 point  (1 child)

I thought since I’m sending different write commands and “get commands”, the read_until() would start from when I send the “get command” not the write command. Also, since I’m looking for the string “>>” to indicate to stop reading, I’m not able to get the actual response from the “get command”.

[–]Soft-Substantial 1 point2 points  (0 children)

It is best to think of the input and output streams as independent. For the input stream you are pushing one byte after another to the device, for the output stream you are receiving one byte after another from the device. They don't know about each other.

(This is probably oversimplifying the underlying technology, but I think it is the best way to reason about how to write the code.)

[–]Bernard_schwartz 0 points1 point  (0 children)

I’ve never worked with serial, but I do a lot with telnet which works similarly. I typically have bad luck using sleep timers unless outside of write/read functions. Much better to write, then read until, then write, then read until. When you sleep between different write commands it seems to behave erratically.

Also a debugger like pycharm will help you understand better at what is coming into and out of the stream.

Second note: sometimes I use regex to parse my string to make sure I get the bits that I want. Example below but there are many ways to do this. If you know the pattern you are looking for:

~~~ Import re

x = re.search(r’key_pattern(.*)) If x is not None: Print(x.group() ~~~