我是C#的新手。
请您告诉我如何获得显示在以下代码的textBox1上的pressureValue的移动平均值。
wrapper.GetDeviceSensorValue(pressure, ref pressureValue);
wrapper.GetDeviceSensorValue(flow, ref flowValue);
this.textBox1.Text = pressureValue.ToString();
this.textBox2.Text = flowValue.ToString();
答案 0 :(得分:0)
下面是我所做的移动平均线。我的压力读数没有任何问题。对于Flow读数,我在高读数方面遇到了问题。例如,我期望的是34L / min,但是我的程序只能读取32至33 L / min。
谢谢。
// get values to test
wrapper.GetDeviceSensorValue(pressure, ref this.vitalPressure);
wrapper.GetDeviceSensorValue(flow, ref this.vitalFlow);
{
int i;
float value1 = 0;
float value2 = 0;
int numReadings =3000000;
float vital1;
float vital2;
for (i = 0; i < numReadings; i++)
{
wrapper.GetDeviceSensorValue(pressure, ref this.vitalPressure);
value1 = value1 + this.vitalPressure;
}
vital1 = value1 / numReadings;
this.textBox1.Text = vital1.ToString("0.##");
System.Threading.Thread.Sleep(1);
for (i = 0; i < numReadings; i++)
{
wrapper.GetDeviceSensorValue(flow, ref this.vitalFlow);
value2 = value2 + this.vitalFlow;
}
vital2 = value2 / numReadings;
this.textBox2.Text = vital2.ToString("0.##");
System.Threading.Thread.Sleep(1);
}