-2

我是 C# 的新手。

您能否告诉我如何获得出现在下面代码的 textBox1 上的压力值的移动平均值。

wrapper.GetDeviceSensorValue(pressure, ref pressureValue);
wrapper.GetDeviceSensorValue(flow, ref flowValue);

this.textBox1.Text = pressureValue.ToString();
this.textBox2.Text = flowValue.ToString();
4

1 回答 1

0

下面是我做的移动平均线。我对压力读数没有任何问题。对于流量读数,我对高读数有疑问。例如,我预计 34 升/分钟,但我的程序只读取 32 到 33 升/分钟。

谢谢你。

            // 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);
                }
于 2018-08-29T23:08:16.947 回答