title: Best approach to parse buffer string in python
body: <p>I'm working on an embedded system that sends commands via Uart. 
  Uart works at 115200 baud</p>
  
  <p>On PC side I want to read these commands, parse them and execute the related action.</p>
  
  <p>I choose python as language to build a script.</p>
  
  <p>This is a typical command received from the embedded system:</p>
  
  <pre><code>S;SEND;40;{"ID":"asg01","T":1,"P":{"T":180}};E
  </code></pre>
  
  <p>Each message starts with S and ends with E. 
  The command associated to the message is "SEND" and the payload length is 40. </p>
  
  <p>My idea is read the bytes coming from the UART and:</p>
  
  <ul>
  <li>check if the message starts with S</li>
  <li>check if the message ends with E</li>
  <li>if the above assumptions are true, split the message in order to find the command and the payload.</li>
  </ul>
  
  <p>Which is the best way to parse the all bytes coming from an asynchronous uart? </p>
  
  <p>My concern regards the lost of message due to wrong (or slow) parsing.</p>
  
  <p>Thanks for the help!</p>
  
  <p>BR,
  Federico</p>