//关闭串口 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(); } }
时间: 2024-10-29 19:10:54