title: How can I trigger buffering of an Observable data stream when a certain value or condition is met?
body: <p>I am using a Reactive Extensions Observable data stream tied to a COM port and I am displaying buffers from that data stream taken over a time interval.</p>
  
  <p>This is my basic Rx code where byte data is returned in 25 millisecond chunks. I want to fire off the generation of the buffer the first time a particular threshold is hit, then do it again only after the previous buffer has been collected.</p>
  
  <pre><code>var o = serialData.Buffer(TimeSpan.FromMilliseconds(25))
                    .ObserveOn(SynchronizationContext.Current);
  var mySerialObserver = o.Subscribe&lt;IList&lt;byte&gt;&gt;(SubscribeAction());
  </code></pre>
  
  <p>The serialData object is an IObservable of a continous stream of byte values coming from a USB COM port. The code for this was adapted from a Bart De Smet post:</p>
  
  <p><a href="http://social.msdn.microsoft.com/Forums/pl-PL/rx/thread/5a12822d-92a6-4ff3-9a37-9bcce83dae0c" rel="nofollow" title="How to implement SerialPort parser with Rx">How to implement SerialPort parser with Rx</a></p>
  
  <p>Using the Rx Buffer(TimeSpan) method I can sample the serialData and display the buffer values on a graph (Using <a href="http://dynamicdatadisplay.codeplex.com/" rel="nofollow">DynamicDataDisplay</a> within my SubscribeAction method).</p>
  
  <p>I would like to extend the functionality to behave like an Oscilloscope Trigger, this might involve invoking the Rx Buffer method at the point when a serialData value exceeds a given threshold value, but not collecting overlapping Buffers (this would be analogous to an Oscilloscope timebase triggering at a certain input voltage but not triggering again until the sweep is complete) </p>
  
  <p>Please can someone give me some ideas of how this might be implemented?</p>