private void OpenSerialPort() { if (commSvc.serialIsOpen) { this.commSvc.CloseSerialPort(); this.btnOpen.Content = "打开串口"; this.txtSerialStatus.Text = commSvc.PortName + "已经关闭"; groupSerialProperties.IsEnabled = false; } else { String portName = (String)this.cmbPortNames.SelectedValue; int baudRate = (int)this.cmbBaudRates.SelectedValue; int dataBits = (int)this.cmbDataBits.SelectedValue; Parity parity = (Parity)this.cmbParitys.SelectedValue; StopBits stopBits = (StopBits)this.cmbStopBits.SelectedValue; //Console.WriteLine(portName, ); if (commSvc.OpenSerialPort(portName, baudRate, dataBits, parity, stopBits)) { this.btnOpen.Content = "关闭串口"; this.txtSerialStatus.Text = commSvc.PortName + "打开成功"; } else { this.txtSerialStatus.Text = commSvc.PortName + "打开失败!"; } groupSerialProperties.IsEnabled = !this.commSvc.serialIsOpen; } }