I am trying to implement a winform application that presents on a line-chart a set of samples (coming form HW device).
I used the INotifyPropertyChanged Interface and bind the chart to the model of the HW device, but it seems that the chart doesn't get updated when the samples are changed at the HW model.
Sorry, if this is too basic (I am more of an embedded guy), but it seems that I am missing the part that connects the INotifyPropertyChanged event to the data binder.
Is there something missing here? or should I implement it differently?
At the WinForm class I wrote the following code to bind the chart to the samples of the HW model The buttons should demonstrate case when the 'ADCSamples' changes:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
StreamChart.Series[0].Points.DataBindY(GSWatch.ADCSamples);
}
private GSWatchModel GSWatch = new GSWatchModel();
private void button1_Click(object sender, EventArgs e)
{
uint[] muki = new uint[128];
for (int i = 0; i < 128; i++)
{
muki[i] = (uint)(i / 10);
}
GSWatch.ADCSamples = muki;
//StreamChart.Series[0].Points.DataBindY(GSWatch.ADCSamples); //The chart is only updated if this line is executed
}
private void button2_Click(object sender, EventArgs e)
{
GSWatch.StartStreamADC();
//StreamChart.Series[0].Points.DataBindY(GSWatch.ADCSamples); //The chart is only updated if this line is executed
}
}
At the HW model I wrote the following code to implement the INotifyPropertyChanged feature:
public class GSWatchModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private uint[] aDCSamples = new uint[128];
public uint[] ADCSamples
{
get
{
return aDCSamples;
}
set
{
aDCSamples = value;
NotifyPropertyChanged();
}
}
public GSWatchModel()
{
CommLink = new GSCommManager();
for (int i = 0; i < 128; i++)
{
aDCSamples[i] = (uint)(i); //initial values for demo
}
}
uint muki = 0;
public void StartStreamADC()
{
GSPacket StreamRequestPacket = new GSPacket(GSPTypes.Stream);
CommLink.SendViaGSWatchLink(StreamRequestPacket);
for (int i = 0; i < 128; i++)
{
aDCSamples[i] = (uint)i / 10; //steps for demonstration
}
NotifyPropertyChanged();
muki += 100;
}
}