码迷,mamicode.com
首页 > 其他好文 > 详细

打开/关闭串口

时间:2015-06-12 10:02:24      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

          //关闭串口
if (((MainForm)this.Owner).serialPort_GPS != null) { try { if (((MainForm)this.Owner).serialPort_GPS.IsOpen) { ((MainForm)this.Owner).serialPort_GPS.Close(); ((MainForm)this.Owner).serialPort_GPS = null; } } catch { checkBox_GPS_Enabled.Checked = true; Form_MessageBox FMB = new Form_MessageBox(); FMB.m_strInfo = "关闭GPS串口失败!\r\n请检查是否被占用!"; FMB.ShowDialog(); } }

  

                //新建并打开串口
          if (((MainForm)this.Owner).serialPort_GPS == null) { try { ((MainForm)this.Owner).serialPort_GPS = new SerialPort( comboBox_GPS_PortName.Text, Convert.ToInt32(comboBox_GPS_BaudRate.Text), (Parity)comboBox_GPS_Parity.SelectedIndex, Convert.ToInt32(comboBox_GPS_DataBits.Text), (StopBits)comboBox_GPS_StopBits.SelectedIndex); //打开GPS串口 ((MainForm)this.Owner).serialPort_GPS.Open(); //设置频率? ((MainForm)this.Owner).SetGSVFreq(); //设置GPS模式 ((MainForm)this.Owner).SetGPSOutMode(); comboBox_GPS_BaudRate.Enabled = false; comboBox_GPS_DataBits.Enabled = false; comboBox_GPS_Parity.Enabled = false; comboBox_GPS_PortName.Enabled = false; comboBox_GPS_StopBits.Enabled = false; textBox_GPS_TestData.Enabled = false; BTN_GPS_PortTest.Enabled = false; BTN_GPS_BackToDefault.Enabled = false; } catch { ((MainForm)this.Owner).serialPort_GPS = null; checkBox_GPS_Enabled.Checked = false; Form_MessageBox FMB = new Form_MessageBox(); FMB.m_strInfo = "打开GPS串口失败!\r\n请检查串口配置!\r\n请检查串口是否被占用!"; FMB.ShowDialog(); } }

  

打开/关闭串口

标签:

原文地址:http://www.cnblogs.com/CESC4/p/4570823.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!