private void tsmi_COMSet_Click(object sender, EventArgs e) { FrmCOMSet frmComSet = new FrmCOMSet(); frmComSet.ShowDialog(); MessageBox.Show("这里会被执行吗?结果好像是会的", "?");//在这里更新状态栏、打开串口、开启定时器等 try { myserialPort.Open(); if (myserialPort.IsOpen) { timer1.Start(); } } catch (Exception) { MessageBox.Show("串口打开故障", "提示!"); //throw; } }
private void Init() { //检查是否存在配置文件、读取配置文件。暂时没有这个功能 //初始化串口 FrmCOMSet frmComSet = new FrmCOMSet(); frmComSet.ShowDialog(); StartDateTime = DateTime.Now; //初始化电源参数信息,额定电压、电流等 TXR1012.MaxFilLimit = 4F; TXR1012.MinFilLimit = 0F; TXR1012.MaxFilPreHeat = 2.6F; TXR1012.MinFilPreHeat = 0F; TXR1012.MaxkV = 50F; TXR1012.MinkV = 0F; TXR1012.MaxmA = 1F; TXR1012.MinmA = 0F; TXR1012.MaxTemp = 100F; TXR1012.MinTemp = -50F; TXR1012.MaxPowerVoltage = 43.9F; TXR1012.MinPowerVoltage = 0F; MData.PowerSupplyType = TXR1012; myserialPort.Open(); //开机打开串口 //初始化初始值,读取一次对电源电压和工作温度和状态进行显示 MData.ReadAll(SlaveAddress, myserialPort); //这个还是有些问题,超时在NModbus里已经有设计 #region 初始化输入界面 //初始输入化界面 if (MData.ComStateFlag) // 通讯读取成功时 { aGauge_kV.Value = 0F; txt_kVSet.Text = aGauge_kV.Value.ToString(); aGauge_mA.Value = 0F; txt_mASet.Text = aGauge_mA.Value.ToString(); txt_FilPreHeat.Text = 0F.ToString(); trackBar_FilLimitSet.Value = 0; txt_FilLimitSet.Text = trackBar_FilLimitSet.Value.ToString(); txt_FilPreHeat.Text = ((float)trackBar_FilLimitSet.Value / 10).ToString(); label_FilLimitHiden.Visible = false; label_kV.Text = MData.kVRead.ToString(); label_mA.Text = MData.mARead.ToString(); label_Power.Text = MData.PowerVoltageRead.ToString() + "V"; label_Temp.Text = MData.TempRead.ToString() + "℃"; label_Filment.Text = MData.FilamentRead.ToString(); //状态显示初始化 if (MData.HVState) { ovalShape_OpenHV.FillColor = Color.Red; ovalShape_CloseHV.FillColor = Color.Gray; } else { ovalShape_OpenHV.FillColor = Color.Gray; ovalShape_CloseHV.FillColor = Color.Lime; } label_InterLockOK.BackColor = Color.GreenYellow; label_InterLockError.BackColor = Color.Gray; label_StateOK.BackColor = Color.GreenYellow; label_StateError.BackColor = Color.Gray; } else // 通讯读取失败时 { aGauge_kV.Value = 0F; txt_kVSet.Text = aGauge_kV.Value.ToString(); aGauge_mA.Value = 0F; txt_mASet.Text = aGauge_mA.Value.ToString(); txt_FilPreHeat.Text = 0F.ToString(); trackBar_FilLimitSet.Value = 0; txt_FilLimitSet.Text = trackBar_FilLimitSet.Value.ToString(); txt_FilPreHeat.Text = ((float)trackBar_FilLimitSet.Value / 10).ToString(); label_FilLimitHiden.Visible = false; label_kV.Text = "----"; label_mA.Text = "----"; label_Power.Text = "----" + "V"; label_Temp.Text = "----" + "℃"; label_Filment.Text = "----"; //状态显示初始化 //if (MData.HVState) //{ ovalShape_OpenHV.FillColor = Color.Gray; ovalShape_CloseHV.FillColor = Color.Gray; //} //else //{ // ovalShape_OpenHV.FillColor = Color.Gray; // ovalShape_CloseHV.FillColor = Color.Lime; //} label_InterLockOK.BackColor = Color.Gray; label_InterLockError.BackColor = Color.Gray; label_StateOK.BackColor = Color.Gray; label_StateError.BackColor = Color.Gray; } #endregion //初始化状态栏 #region 初始化状态栏 StatusStripDisplay(); #endregion //初始化显示值 }