/// <summary>更新所有状态</summary> public void UpdateModuleStatus() { if (InvokeRequired) { Invoke(new Action(UpdateModuleStatus)); return; } if (null == _module) { return; } for (int i = 0; i < _module.EncoderChannels; i++) { UcCmprTrgChn ucEnc = gbChns.Controls[i] as UcCmprTrgChn; ucEnc.UpdateChnStatus(); } int err = 0; for (int i = 0; i < _module.TrigChannels; i++) { int count = 0; err = _module.GetTriggedCount(i, out count); if (0 != err) { lstTrigTimeTbs[i].Text = "Err"; } else { lstTrigTimeTbs[i].Text = count.ToString(); } } }
bool isChkEnableSetting = false; //主动更新CheckBox控件值 //根据通道数量布置界面 void AdjustUI() { if (InvokeRequired) { Invoke(new Action(AdjustUI)); return; } gbChns.Controls.Clear(); gbTrigs.Controls.Clear(); //lstTrigIdLbs.Clear(); lstTrigEnableChks.Clear(); lstTrigTimeTbs.Clear(); lstResetTimeBts.Clear(); lstSwTrigBts.Clear(); if (null == _module) { ShowTips("模块对象为空"); return; } int err = 0; int locX = 3, locY = 30; for (int i = 0; i < _module.EncoderChannels; i++) { UcCmprTrgChn ucChn = new UcCmprTrgChn(); ucChn.OnTxtMsg += ShowTips; ucChn.Location = new Point(locX, locY); string encName = _encChnIDs == null ? null : (_encChnIDs.Length > i ? _encChnIDs[i] : null); ucChn.SetModuleChn(_module, i, encName, _trigChnIDs); locY += ucChn.Height + 3; gbChns.Controls.Add(ucChn); } locY = 30; for (int i = 0; i < _module.TrigChannels; i++) { ///通道ID标签 Label lbTrigID = new Label(); lbTrigID.Text = _trigChnIDs != null && (_trigChnIDs.Length > i) ? _trigChnIDs[i] : ("通道_" + i.ToString()); lbTrigID.Location = new Point(3, locY + 5); lbTrigID.Width = 100; gbTrigs.Controls.Add(lbTrigID); ///通道使能 CheckBox chkEnable = new CheckBox(); chkEnable.Text = "使能"; chkEnable.Location = new Point(lbTrigID.Right + 3, locY); gbTrigs.Controls.Add(chkEnable); lstTrigEnableChks.Add(chkEnable); chkEnable.CheckedChanged += OnTrigEnableCheckedChange; bool isEnable = false; err = _module.GetTrigEnable(i, out isEnable); isChkEnableSetting = true; if (err != 0) { ShowTips("获取 " + lbTrigID.Text + " 使能状态失败,错误信息:" + _module.GetErrorInfo(err)); chkEnable.Checked = false; } else { chkEnable.Checked = isEnable; } isChkEnableSetting = false; ///触发次数 Label lbTrigTimes = new Label(); lbTrigTimes.Text = "次数"; lbTrigTimes.Location = new Point(chkEnable.Right + 3, locY + 5); gbTrigs.Controls.Add(lbTrigTimes); TextBox tbTrigTimes = new TextBox(); tbTrigTimes.ReadOnly = true; tbTrigTimes.BackColor = SystemColors.Control; tbTrigTimes.Location = new Point(lbTrigTimes.Right + 3, locY); gbTrigs.Controls.Add(tbTrigTimes); lstTrigTimeTbs.Add(tbTrigTimes); Button btResetTimes = new Button(); btResetTimes.Location = new Point(tbTrigTimes.Right + 3, locY); btResetTimes.Text = "置0"; gbTrigs.Controls.Add(btResetTimes); lstResetTimeBts.Add(btResetTimes); btResetTimes.Click += OnResetTrigTimesButtonClick; ///软触发 Button btSoftwareTrig = new Button(); btSoftwareTrig.Location = new Point(btResetTimes.Right + 3, locY); btSoftwareTrig.Text = "软触发"; gbTrigs.Controls.Add(btSoftwareTrig); lstSwTrigBts.Add(btSoftwareTrig); btSoftwareTrig.Click += OnSoftwareTrigButtonClick; locY += btSoftwareTrig.Height + 3; } UpdateModuleStatus(); }