示例#1
0
        private void WriteTC(byte tag)
        {
            float tempAD  = 0;
            float lowerAD = 0;
            float upperAD = 0;

            if (!float.TryParse((this.Controls["txtTempAD" + tag.ToString()] as TextBox).Text, out tempAD))
            {
                MessageBox.Show("温度AD不能转化成数值");
                (this.Controls["txtTempAD" + tag.ToString()] as TextBox).Focus();
                return;
            }
            if (!float.TryParse((this.Controls["txtLow" + tag.ToString()] as TextBox).Text, out lowerAD))
            {
                MessageBox.Show("压力零点AD不能转化成数值");
                (this.Controls["txtLow" + tag.ToString()] as TextBox).Focus();
                return;
            }
            if (!float.TryParse((this.Controls["txtUpper" + tag.ToString()] as TextBox).Text, out upperAD))
            {
                MessageBox.Show("压力满度AD不能转化成数值");
                (this.Controls["txtUpper" + tag.ToString()] as TextBox).Focus();
                return;
            }
            TemperatureCompensation tc = new TemperatureCompensation()
            {
                TemperatureAD = tempAD, LowerRangeAD = lowerAD, UpperRangeAD = upperAD
            };
            bool ret = HartDevice.WriteTC(tag, tc);

            MessageBox.Show(ret ? "下载成功" : HartDevice.GetLastError(), "结果", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#2
0
        private void ReadTC(byte tag)
        {
            TemperatureCompensation tc = HartDevice.ReadTC(tag);

            (this.Controls["txtTempAD" + tag.ToString()] as TextBox).Text = tc != null?tc.TemperatureAD.ToString() : null;

            (this.Controls["txtLow" + tag.ToString()] as TextBox).Text = tc != null?tc.LowerRangeAD.ToString() : null;

            (this.Controls["txtUpper" + tag.ToString()] as TextBox).Text = tc != null?tc.UpperRangeAD.ToString() : null;
        }
示例#3
0
            private static double RawToTemp(int adcTemperature, TemperatureCompensation temperatureCompensation)
            {
                var var1 = ((adcTemperature / 16384.0M) - (temperatureCompensation.T1 / 1024.0M)) *
                           temperatureCompensation.T2;
                var var2  = ((adcTemperature / 131072M) - (temperatureCompensation.T1 / 8192.0M));
                var var3  = var2 * ((adcTemperature / 131072.0M) - (temperatureCompensation.T1 / 8192.0M));
                var var4  = var3 * (temperatureCompensation.T3 * 16.0M);
                var tFine = var1 + var4;

                return(Convert.ToDouble(tFine / 5120.0M));
            }
示例#4
0
        public bool set_hv_compensation(TemperatureCompensation mode, float temp_coeff)
        {
            string _mode = "digital";

            switch (mode)
            {
            case TemperatureCompensation.DISABLE_COMPENSATION:
                _mode = "digital";
                break;

            case TemperatureCompensation.ENABLE_COMPENSATION:
                _mode = "temperature";
                break;
            }
            string JSON_COMMAND = "{\"command\": \"SET_CHANNEL_CONFIG\", \"channel_config\": [{\"id\": 0, \"HV_MODE\": " +
                                  _mode + ", \"TCoeff\": " +
                                  temp_coeff.ToString().Replace(",", ".") + "}], \"store_flash\": false}";

            return(HttpPostJson(ispector_URL + "/set_config.cgi", JSON_COMMAND));
        }