来自传感器c的读数的移动平均值

问题描述 投票:-2回答:1

我是C#的新手。

你能告诉我如何获得下面代码中textBox1上显示的压力值的移动平均值。

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

this.textBox1.Text = pressureValue.ToString();
this.textBox2.Text = flowValue.ToString();
flow moving-average meter pressure
1个回答
0
投票

以下是我所做的移动平均线。我对压力读数没有任何问题。对于流量读数,我的高读数问题。例如,我期望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);
                }
© www.soinside.com 2019 - 2024. All rights reserved.