9 thoughts on “

  1. Hello guys


    I was reading the Python manual (rev 13), paragraph 3.4.3, about


    It says about the output: "…it  is  the  string  containing  the  data  received  at  command execution time.  "


    But what if the data source produces an "endless" serial data stream, such as a GPS receiver, outputting NMEA sentences one after another?  Will this one single line of code read a string until <CR>, or <LF> is encountered; or maybe until the input buffer of 4096 bytes flows over?


     BR, Tom

    1. During script execution data arrived at serial port accumulates in the input buffer, ser_read takes what it finds in the buffer when is executed, and returns immediately.

  2. Thanks Cosmin. Does this mechanism guarantee that no data is lost, and no data is duplicated, on the condition that a sentence is performed often enough, so that the input buffer of 4096 bytes will not overflow?


    Would you like to point me to some example about how to arrange the input mechanism in Python? Especially in this case, where there is no need to wait for input, but rather be quick to process it and keep ahead of the constant data flow?



    1. Well Tom, for such cases flow control was invented 🙂

      "Often enough" depends of stream speed and other activities that need to be accomplished, if you have network jobs you will be stuck sooner or later in longer waiting periods but with clever arrangement I think you can arrive to a good setup even without flow control. Keep a function called periodic to fetch from input data and accumulate in your own buffer; call it even when you don’t need data, just to empty the input buffer, and have data available for further processing, at will. But keep a watch of how large your buffer can be!



  3. Cosmin, I know flow control. Unfortunately, my data source does not have any sort of flow control.


    Thanks for your hints about the periodic function. I will take alook at it.



    1. Hi Cosmin


      Now I tried to find something about the periodic function mentioned earlier by you. My sources were Oreilly: Learning.Python 4th Edition Sep.2009 and Oreilly: Python Pocket Reference 4th Edition Sep.2009 but could not get a hit on the name periodic. 


      Can you please point me to some relevant source?


      Thanks, Tom




      1. Ah Tom, I think I created a confusion!

        The correct wording must be "called periodically" and not "called periodic", ie a function which you’ll call yourself at regular time intervals to do a job. Sorry Embarassed

  4. Hi Cosmin


    OK, I see. But no worry 🙂 I will try to make something similar myself.


    Anyway, wouldn’t it be nice to have such an inbuilt function! Should be useful for many purposes. Especially, if it allowed the module to otpionally go asleep and save power.