/// <summary> /// 串口开关控制 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSerialPortSwitch_Click(object sender, EventArgs e) { if (btnSerialPortSwitch.Text == "打开串口") { spb.OpenCom(cc.GetConfigComData(), out string strError); if (strError != "null") { MessageBox.Show(strError); } else { Console.WriteLine("开启{0}端口成功。", cc.PortName); btnSerialPortSwitch.Text = "关闭串口"; } } else { spb.CloseCom(out string strError); if (strError != "null") { MessageBox.Show(strError); } else { Console.WriteLine("关闭端口成功。"); btnSerialPortSwitch.Text = "打开串口"; } } }
/// <summary> /// 打开/关闭串口按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSerialPortSwitch_Click(object sender, EventArgs e) { if (btnSerialPortSwitch.Text == "打开串口") { serialPortHelper.OpenCom(configCom.GetConfigComData(), out string strError); if (strError != "null") { MessageBox.Show(strError); } else { Console.WriteLine("开启{0}端口成功。", configCom.PortName); GroupEnable(gbSerialWrite, true); btnSerialPortSwitch.Text = "关闭串口"; ClearListViewSerialReceviedValue(); AddSerialWrite("AT"); SaveSerialConfig(configCom.GetConfigComData()); } } else { serialPortHelper.CloseCom(out string strError); if (strError != "null") { MessageBox.Show(strError); } else { Console.WriteLine("关闭端口成功。"); GroupEnable(gbSerialWrite, false); btnSerialPortSwitch.Text = "打开串口"; } } }
/// <summary> /// 打开/关闭串口按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSerialPortSwitch_Click(object sender, EventArgs e) { if (btnSerialPortSwitch.Text == "打开") { serialPortHelper.OpenCom(configCom.GetConfigComData(), out string strError); if (strError != "null") { MessageBox.Show(strError); } else { Console.WriteLine("开启{0}端口成功。", configCom.PortName); toolBleWrite.Enabled = !checkAutoLinkBle.Checked; btnSerialPortSwitch.Text = "关闭"; //ClearListViewSerialReceviedValue(); AddSerialWrite("AT"); //SaveSerialConfig(configCom.GetConfigComData()); } } else { serialPortHelper.CloseCom(out string strError); if (strError != "null") { MessageBox.Show(strError); } else { Console.WriteLine("关闭端口成功。"); toolBleWrite.Enabled = false; btnSerialPortSwitch.Text = "打开"; } } }
/// <summary> /// 串口开关按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSerialPortSwitch_Click(object sender, EventArgs e) { Button btn = (Button)sender; ConfigCom cc = (btn.Tag.ToString() == "1") ? configCom1 : configCom2; SerialPortHelper spb = (btn.Tag.ToString() == "1") ? serialPort1 : serialPort2; CheckBox chkTimer = (btn.Tag.ToString() == "1") ? chkSerialWriteLoop1 : chkSerialWriteLoop2; GroupBox grp = btn.Parent as GroupBox; if (btn.Text == "打开串口") { string strError; try { spb.OpenCom(cc.GetConfigComData(), out strError); } catch (Exception err) { strError = err.Message; } if (strError != "null") { MessageBox.Show(strError); } else { cc.GetDetectCom().Close(); Console.WriteLine("开启{0}端口成功。", cc.PortName); btn.Text = "关闭串口"; GroupBoxEnable(grp, false); } } else { spb.CloseCom(out string strError); if (strError != "null") { MessageBox.Show(strError); } else { cc.GetDetectCom().Open(); Console.WriteLine("关闭端口成功。"); btn.Text = "打开串口"; GroupBoxEnable(grp, true); chkTimer.Checked = false; } } }