title: How to use Reactive Extensions to parse a stream of characters from a serial port?
body: <p>I need to parse a stream of serial data coming from a test instrument, and this seems to be an excellent application for Reactive Extensions.</p>
  
  <p>The protocol is very simple...each "packet" is a single letter followed by numeric digits. The number of numeric digits is fixed for each packet type, but can vary between packet types.  e.g.</p>
  
  <p>...A1234B123456C12...</p>
  
  <p>I am trying to break this up into an Observable of Strings, e.g.</p>
  
  <p>"A1234" "B123456" "C12" ...</p>
  
  <p>Thought this would be simple, but don't see the obvious way to approach this (I have some experience with LINQ, but am new to Rx).</p>
  
  <p>Here's the code I have so far, that produces Observable of chars from the serial port's SerialDataReceived event.</p>
  
  <pre><code>        var serialData = Observable
                              .FromEventPattern&lt;SerialDataReceivedEventArgs&gt;(SerialPortMain, "DataReceived")
                              .SelectMany(_ =&gt; 
                              {
                                  int dataLength = SerialPortMain.BytesToRead;
                                  byte[] data = new byte[dataLength];
                                  int nbrDataRead = SerialPortMain.Read(data, 0, dataLength);
  
                                  if (nbrDataRead == 0)
                                      return  new char[0]; 
  
                                   var chars = Encoding.ASCII.GetChars(data);
  
                                   return chars; 
                              });
  </code></pre>
  
  <p>How can I transform serialData to Observable of String, where each string is a packet?</p>