Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8621605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:51:26+00:00 2026-06-12T06:51:26+00:00

I am using a Reactive Extensions Observable data stream tied to a COM port

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:51:28+00:00Added an answer on June 12, 2026 at 6:51 am

    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.

        static IObservable<IObservable<T>> TriggeredSweep<T>(
            this IObservable<T> source,
            Func<T, bool> triggerCondition,
            Func<T, bool> sweepEnd
            )
        {
            source = source.Publish().RefCount();
            return source.Window(() => source.Where(triggerCondition).Sample(source.Where(sweepEnd)))
                         .Select(s => s.SkipWhile(v => !triggerCondition(v)));
    
        }
    

    The best way to test this out is on the very Oscilloscope model on which this is predicated:

            double period = 1000 / 0.5; //0.5 Hz
            int cycles = 4;             //cycles to display
            int quantization = 100;     //cycles to display            
            int amplitude = 10;         //signal peak            
    
            int range = quantization * cycles;    //full range 
    
            //Sine wave generator for n cycles
            //makes tuple of (t, sin(t))
            var source = Observable.Interval(TimeSpan.FromMilliseconds(period / range))
                                   .Select(s => s % (range + 1))
                                   .Select(s => Tuple.Create(s, amplitude * Math.Sin((double)s / ((double)range / (double)cycles) * 2 * Math.PI)));
    
    
            source.TriggeredSweep(
                value => value.Item2 > 5, //Trigger when Signal value > 5
                value => value.Item1 / quantization >= cycles //end sweep when all cycles are done
                )
                  .Subscribe(window =>
                  {
                      Console.Clear(); //Clear CRO Monitor
    
                      window.Subscribe(value =>
                      {
                          //Set (x, y)
                          Console.CursorLeft = (int)((double)value.Item1 / range * (Console.WindowWidth - 1));
                          Console.CursorTop = (int)((amplitude - value.Item2) / (2 * amplitude) * (Console.WindowHeight - 1));
    
                          //draw
                          Console.Write("x");
                      });
                  });
    
            //prevent close
            Console.ReadLine();
    

    Output:

        xxx                   xxxx                   xxx                   xxxx
       xx  x                  x  x                  xx  x                  x  x
       x   x                 xx   x                 x   x                 xx   x
      xx    x                x    x                xx    x                x    x
      x     x               xx     x               x     x               xx     x
      x      x              x      x               x      x              x      x
      x      x              x      x              xx      x              x      x
             x              x       x             x       x              x       x
             x             x        x             x       x             x        x
              x            x        x             x        x            x        x
              x            x        xx           x         x            x        xx
              x           x          x           x         x           x          x
               x          x          x           x          x          x          x
               x          x          x           x          x          x          x           x
               x          x          x          x           x          x          x          x
               x          x           x         x           x          x           x         x
               xx        x            x         x           xx        x            x         x
                x        x            x        x             x        x            x        x
                x        x             x       x             x        x             x       x
                x       x              x       x             x       x              x       x
                 x      x              x      xx              x      x              x      xx
                 x      x               x     x               x      x               x     x
                 x     xx               x     x               x     xx               x     x
                  x    x                x    xx                x    x                x    xx
                  x   xx                 x   x                 x   xx                 x   x
                   x  x                  x  xx                  x  x                  x  xx
                   xxxx                   xxx                   xxxx                   xxx
                    x                      x                     x                      x
    

    I hope this code might be useful for testing simple signal processing functions using Rx. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Reactive Extensions to create anonymous Observable to perform web request, post-process
I'm using the Reactive Extensions (Rx) and a repository pattern to facilitate getting data
I'm using reactive extensions in my wp7 app that I'm making and I wish
I'm currently using the Parallel Extensions that are part of Reactive Extensions for .Net(Rx)
I'm creating multiple asynchronous web requests using IObservables and reactive extensions. So this creates
I have the following code in a WPF application using Reactive Extensions for .NET:
How would you structure a simple simulation engine using Reactive Extensions? For example, suppose
I'm using RX extensions and WF4 to create a workflow which reacts to observable
I'm using Reactive Extensions for easy event handling in my ViewModels (Silverlight and/or Wp7
I am using Reactive extensions for NET (Rx) with Caliburn.Micro in my WPF app.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.