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.
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.
var o = serialData.Buffer(TimeSpan.FromMilliseconds(25))
.ObserveOn(SynchronizationContext.Current);
var mySerialObserver = o.Subscribe<IList<byte>>(SubscribeAction());
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:
How to implement SerialPort parser with Rx
Using the Rx Buffer(TimeSpan) method I can sample the serialData and display the buffer values on a graph (Using DynamicDataDisplay within my SubscribeAction method).
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)
Please can someone give me some ideas of how this might be implemented?
Buffer would only release all your values until the buffer closes, which is not very useful for a real-time graph.
You’d have to split up the values into non-overlapping windows – which starts on a given trigger, and closes when the sweep condition is complete – a window for one complete sweep cycle.
Unfortunately, the window will still give us values when it starts, so we’re going to have to skip all the values which come in before the trigger fires.
The best way to test this out is on the very Oscilloscope model on which this is predicated:
Output:
I hope this code might be useful for testing simple signal processing functions using Rx. 🙂