Ejemplo n.º 1
0
        public void DblClickOnHoldRegItem(int nIndexOfList, int nSubIndex)
        {
            RegisterItem register   = null;
            int          nAddrIndex = (int)(nSubIndex / 3) * 3;
            uint         uiAddr     = 0;

            frm8BitsSetting.HexToUint(listView1.Items[nIndexOfList].SubItems[nAddrIndex].Text, ref uiAddr);
            if (_device._dicHoldRegs.ContainsKey((int)uiAddr))
            {
                if ((nSubIndex % 3) == 2) //双击在数据上
                {
                    _bEditItem        = true;
                    _nEiditItemIndex  = nIndexOfList;
                    _nEditSubItemItem = nSubIndex;
                    listView1.ShowTextBoxOnItem(nIndexOfList, nSubIndex);
                    //timer1.Interval = 200;
                    //timer1.Start();
                }
                else
                {
                    register = _device._dicHoldRegs[(int)uiAddr];
                    ShowChangeRegisterDlg(register, true);
                }
            }
        }
Ejemplo n.º 2
0
        public void AddHoldRegister(RegisterItem register)
        {
            ListViewItem listItem     = null;
            int          nInsertIndex = -1;

            if (_nMaxHoldRegIndex >= 0)
            {
                nInsertIndex = _nMaxHoldRegIndex;
            }
            else if (_nMaxInputRegIndex >= 0)
            {
                nInsertIndex = _nMaxInputRegIndex;
            }
            else if (_nMaxSwitchIndex >= 0)
            {
                nInsertIndex = _nMaxSwitchIndex;
            }
            else if (_nMaxCoilIndex >= 0)
            {
                nInsertIndex = _nMaxCoilIndex;
            }

            if (nInsertIndex == -1 || _nSubIndexOfInputRegItem > 8 || _nMaxHoldRegIndex < 0)
            {
                listItem = new ListViewItem();
                _nSubIndexOfHoldRegItem = 0;
            }
            else
            {
                listItem = this.Items[nInsertIndex];
            }

            if (_nSubIndexOfHoldRegItem == 0)
            {
                listItem.SubItems[0].BackColor = aItemsHeadColor[(int)ListItemType.HoldRegister];;
                listItem.SubItems[0].Text      = string.Format("{0:X4}", register._nStartAddr);
                listItem.SubItems.Add(register._strName);
                listItem.SubItems.Add("");

                if (nInsertIndex == -1 || this.Items.Count == (nInsertIndex + 1))
                {
                    this.Items.Add(listItem);
                }
                else
                {
                    this.Items.Insert(nInsertIndex + 1, listItem);
                }
            }
            else
            {
                listItem.SubItems.Add(string.Format("{0:X4}", register._nStartAddr));
                listItem.SubItems.Add(register._strName);
                listItem.SubItems.Add("");
            }

            listItem.UseItemStyleForSubItems = false;
            _nSubIndexOfHoldRegItem         += 3;
            _nMaxHoldRegIndex = listItem.Index;
        }
Ejemplo n.º 3
0
        public void ChangeRegister(bool bHoldReg, RegisterItem register)
        {
            int nIndexOfName = (int)(_nClickSubIndex / 3) * 3 + 1;

            if (listView1.Items[_nClickIndex].SubItems[nIndexOfName].Text != register._strName)
            {
                listView1.Items[_nClickIndex].SubItems[nIndexOfName].Text = register._strName;
            }
        }
Ejemplo n.º 4
0
        public void ShowChangeRegisterDlg(RegisterItem register, bool bHoldReg)
        {
            frmRegisterSetting dlgRegisterSetting = new frmRegisterSetting(register);

            dlgRegisterSetting._bHoldRegister = bHoldReg;
            dlgRegisterSetting._bAddRegister  = false;
            dlgRegisterSetting.SetRegister    = new frmRegisterSetting.DelegateSetRegister(ChangeRegister);
            dlgRegisterSetting.ShowDialog();
        }
Ejemplo n.º 5
0
 public void AddInputRegister(RegisterItem register)
 {
     if (_dicInputRegs == null)
     {
         _dicInputRegs = new SerializableDictionary <int, RegisterItem>();
     }
     _dicInputRegs.Add(register._nStartAddr, register);
     register._aData = new byte[register._nLength];
     _bModified      = true;
 }
Ejemplo n.º 6
0
 public void AddReister(bool bHoldReg, RegisterItem register)
 {
     if (bHoldReg)
     {
         listView1.AddHoldRegister(register);
     }
     else
     {
         listView1.AddInputRegister(register);
     }
 }
Ejemplo n.º 7
0
        public void DblClickOnInputRegItem(int nIndexOfList, int nSubIndex)
        {
            RegisterItem register   = null;
            int          nAddrIndex = (int)(nSubIndex / 3) * 3;
            uint         uiAddr     = 0;

            frm8BitsSetting.HexToUint(listView1.Items[nIndexOfList].SubItems[nAddrIndex].Text, ref uiAddr);
            if (_device._dicInputRegs.ContainsKey((int)uiAddr))
            {
                register = _device._dicInputRegs[(int)uiAddr];
                ShowChangeRegisterDlg(register, false);
            }
        }
        public frmRegisterSetting(RegisterItem register)
        {
            InitializeComponent();

            for (int nIndex = 0; nIndex < aType.Length; nIndex++)
            {
                comboBoxType.Items.Add(aType[nIndex]);
            }

            textBoxAddr.Text           = string.Format("{0:X4}", register._nStartAddr);
            textBoxAddr.Enabled        = false;
            textBoxName.Text           = register._strName;
            comboBoxType.SelectedIndex = register._nType;
            textBoxUpperLimit.Text     = register._strUpperLimit;
            textBoxLowerLimit.Text     = register._strLowerLimit;
            textBoxCoefficient.Text    = register._dCoefficient.ToString();
            _register = register;
        }
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            if (textBoxAddr.Text == "" || textBoxName.Text == "" || comboBoxType.SelectedIndex == -1)
            {
                MessageBox.Show("寄存器地址、名称、类型不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            uint uiAddr = 0;

            if (!frm8BitsSetting.HexToUint(textBoxAddr.Text, ref uiAddr))
            {
                MessageBox.Show("请输入正确的寄存器地址!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                Single sngCoefficient = Convert.ToSingle(textBoxCoefficient.Text);
                if (!_bHoldRegister)
                {
                    string strErr = "";
                    if ((textBoxUpperLimit.Text != "" && !CheckValue(textBoxUpperLimit.Text, comboBoxType.SelectedIndex, sngCoefficient, ref strErr)) ||
                        (textBoxLowerLimit.Text != "" && !CheckValue(textBoxLowerLimit.Text, comboBoxType.SelectedIndex, sngCoefficient, ref strErr)))
                    {
                        MessageBox.Show(string.Format("请输入正确的门限值({0})!", strErr), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

                if (_bAddRegister)
                {
                    _register = new RegisterItem();
                }

                _register._nStartAddr    = (int)uiAddr;
                _register._strName       = textBoxName.Text;
                _register._strUpperLimit = textBoxUpperLimit.Text;
                _register._strLowerLimit = textBoxLowerLimit.Text;
                _register._nLength       = (int)numUpDownLength.Value;
                _register._dCoefficient  = sngCoefficient;
                _register._nType         = comboBoxType.SelectedIndex;

                if (_bAddRegister)
                {
                    if ((_bHoldRegister && _device.CheckAddHoldRegAddr((int)uiAddr, _register._nLength)) || (!_bHoldRegister && _device.CheckAddInputRegAddr((int)uiAddr, _register._nLength)))
                    {
                        AddRegister(_bHoldRegister, _register);
                        if (_bHoldRegister)
                        {
                            _device.AddHoldRegister(_register);
                        }
                        else
                        {
                            _device.AddInputRegister(_register);
                        }
                    }
                }
                else
                {
                    SetRegister(_bHoldRegister, _register);
                    Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }