Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm currently creating a program that reads out data sent via a COM port and then plots it live in a diagram. The data is displayed using the MVVM principle, which works fine when data is sent at around 10Hz. However, the device the data is being read from can go up to a refresh rate of 1 kHz, which means 1000 datasets per minute. This works fine for displaying and updating simple textboxes, however it breaks the diagram because the updating is happening too fast.

What I think I need to do now is limit the amount of update events that is sent to the subscribed classes and pages, so that only a limited amount of data is sent through, which gives the diagram a chance to draw properly. Is there a way to limit this automatically, or what code adjustments would you suggest to do just that manually?

A small code snippet from my collection changed event:

void dataItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
    NotifyPropertyChanged("dataItems");
    NotifyPropertyChanged("lastItem");

    // update any charts
    NotifyPropertyChanged("AccelXData");
    NotifyPropertyChanged("AccelYData");
    NotifyPropertyChanged("AccelZData");
}

// handle property changes
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
    var handler = this.PropertyChanged;
    if (handler != null)
        handler(this, new PropertyChangedEventArgs(propertyName));
}

Every dataset also has an ID that maybe can be used to check when to update manually, as an idea.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
232 views
Welcome To Ask or Share your Answers For Others

1 Answer

A better approach would to remove the calls to NotifyPropertyChanged whenever the data changes.

Create a timer and refresh on the timer. That way you can control the refresh rate, and it is not bound to the rate at which the data arrives.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...