Python Forum

Full Version: PySerial Question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I have installed PySerial and have been playing with its capabilities. I am somewhat new all around to Python as well as PySerial. I am looking to see if I can write a routine that would allow the Python script to wait until a specific message is displayed across the serial port? For instance, if I wanted to do print('Hello') every time the word Geoffrey came across the serial port? I think I might start with a while statement, but beyond that I am puzzled as to how to get the system to wait for an event that matches the criteria.

Thanks!
If you run your serial process as a thread, you can have it wait for a message.
See: http://greenteapress.com/wp/semaphores/ to get some knowledge on this.
Threading is an interesting approach. I will have to research this and try it. I've seen some people implementing the time.sleep values, etc. with conditional IF statements, but I think there might be a better or easier way that I am not thinking of.