//从本地导入串口配置 public NewSerialPort(string name) { InitializeComponent(); Name = name; setting = (NewSerialPortSetting)DataAction.SaveStatic.ReadBinF(Name); SerialPort _serialPort = new SerialPort(setting._port, setting._baudrate, setting._parity, setting._databit, setting._stopbit); SerialPort = _serialPort; SerialPort.DataReceived += new SerialDataReceivedEventHandler(NewserialPort_DataReceived); }
private void button7_Click(object sender, EventArgs e) { try { NewSerialPortSetting setting = (NewSerialPortSetting)DataAction.SaveStatic.ReadBinF(Parent.Text); ANDserial = new NewSerialPort(setting._port, setting._baudrate, setting._parity, setting._databit, setting._stopbit); ANDserial.Open(); if (ANDserial.IsOpen) { this.BackColor = Color.LightGreen; } } catch { } }
private void NewSerialPort_Load(object sender, EventArgs e) { comboBox1.DataSource = SerialPort.GetPortNames(); comboBox2.SelectedIndex = 5; comboBox3.DataSource = Enum.GetNames(typeof(Parity)); comboBox4.SelectedIndex = 0; comboBox5.DataSource = Enum.GetNames(typeof(StopBits)); comboBox5.SelectedIndex = 1; try { NewSerialPortSetting setting = (NewSerialPortSetting)DataAction.SaveStatic.ReadBinF(this.Name); comboBox1.SelectedItem = setting._port; comboBox2.SelectedItem = setting._baudrate.ToString(); comboBox3.SelectedItem = setting._parity.ToString(); comboBox4.SelectedItem = setting._databit.ToString(); comboBox5.SelectedItem = setting._stopbit.ToString(); } catch { } }
//从本地导入串口配置 public NewSerialPort(string name) { InitializeComponent(); Name = name; try { Setting = (NewSerialPortSetting)FastData.SaveStatic.ReadBinF(Name); } catch { MessageBox.Show(Name + "--串口配置失败"); _setting = new NewSerialPortSetting(); _setting._port = "COM1"; _setting._baudrate = 9600; _setting._databit = 7; _setting._stopbit = StopBits.One; _setting._parity = Parity.Even; } SerialPort _serialPort = new SerialPort(Setting._port, Setting._baudrate, Setting._parity, Setting._databit, Setting._stopbit); SerialPort = _serialPort; //SerialPort.DataReceived += new SerialDataReceivedEventHandler(NewserialPort_DataReceived); }