Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (cmbSensorCode.SelectedIndex < 0)
            {
                MessageBox.Show("没有选择传感器代码", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (cmbSensorMode.SelectedIndex < 0)
            {
                MessageBox.Show("没有选择工作模式", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            bool ret = HartDevice.WritePVSensorMode((SensorMode)cmbSensorMode.SelectedIndex, (SensorCode)(cmbSensorCode.SelectedIndex + 2));

            MessageBox.Show(ret ? "设置成功" : HartDevice.GetLastError(), "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            if (ret)
            {
                OutputInfo oi = HartDevice.ReadOutput();
                lblRangeUnit.Text = oi != null?UnitCodeDescr.GetDescr(oi.PVUnitCode) : null;

                txtPVLower.Text = oi != null?oi.LowerRangeValue.ToString() : null;

                txtPVUpper.Text = oi != null?oi.UpperRangeValue.ToString() : null;

                SensorInfo si = HartDevice.ReadPVSensor();
                txtSensorLower.Text = si != null?si.LowerLimit.ToString() : null;

                txtSensorUpper.Text = si != null?si.UpperLimit.ToString() : null;

                lblUnit1.Text = si != null?UnitCodeDescr.GetDescr((UnitCode)si.UnitCode) : null;
            }
        }
Beispiel #2
0
        public void ReadData()
        {
            try
            {
                button1.Enabled = HartDevice != null && HartDevice.IsConnected;
                button3.Enabled = HartDevice != null && HartDevice.IsConnected;
                if (HartDevice != null && HartDevice.IsConnected)
                {
                    OutputInfo oi = HartDevice.ReadOutput();
                    lblRangeUnit.Text = oi != null?UnitCodeDescr.GetDescr(oi.PVUnitCode) : null;

                    txtPVLower.Text = oi != null?oi.LowerRangeValue.ToString() : null;

                    txtPVUpper.Text = oi != null?oi.UpperRangeValue.ToString() : null;

                    SensorInfo si = HartDevice.ReadPVSensor();
                    txtSensorLower.Text = si != null?si.LowerLimit.ToString() : null;

                    txtSensorUpper.Text = si != null?si.UpperLimit.ToString() : null;

                    lblUnit1.Text = si != null?UnitCodeDescr.GetDescr((UnitCode)si.UnitCode) : null;

                    SensorMode?sm = HartDevice.ReadSensorMode();
                    SensorCode?sc = HartDevice.ReadSensorCode();
                    cmbSensorMode.SelectedIndex = sm != null ? (int)sm.Value : -1;
                    cmbSensorCode.SelectedIndex = sc != null ? (int)sc.Value - 2 : -1;
                }
            }
            catch (Exception)
            {
            }
        }
        private void ReadPV_Thread()
        {
            try
            {
                while (_Running)
                {
                    if (HartDevice == null || !HartDevice.IsConnected)
                    {
                        this.Invoke((Action)(() => { btnRealTime.Text = "实时采集"; }));
                        _ReadPV = null;
                        return;
                    }
                    DeviceVariable pv = HartDevice.ReadPV(false);
                    CurrentInfo    ci = HartDevice.ReadCurrent(false);
                    Action         a  = delegate()
                    {
                        if (pv != null)
                        {
                            lblPVUnit.Text = pv != null?UnitCodeDescr.GetDescr(pv.UnitCode) : null;

                            txtPV.Text = pv != null?pv.Value.ToString() : string.Empty;
                        }
                        if (ci != null)
                        {
                            txtCurrent.Text = ci != null?ci.Current.ToString() : string.Empty;

                            txtPercentOfRange.Text = ci != null?ci.PercentOfRange.ToString() : string.Empty;
                        }
                    };
                    this.Invoke(a);
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception)
            {
            }
            finally
            {
                _ReadPV = null;
            }
        }