private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (Serial_port.IsOpen) { Serial_port.Close(); } }
private void cbData_SelectedIndexChanged(object sender, EventArgs e) { if (Serial_port.IsOpen) { Serial_port.Close(); } Serial_port.DataBits = Convert.ToInt32(cbData.Text); }
private void cbRate_SelectedIndexChanged(object sender, EventArgs e) { if (Serial_port.IsOpen) { Serial_port.Close(); } Serial_port.BaudRate = Convert.ToInt32(cbRate.Text); }
private void cbCom_SelectedIndexChanged(object sender, EventArgs e) { if (Serial_port.IsOpen) { Serial_port.Close(); // Nếu đang mở Port thì phải đóng lại } Serial_port.PortName = cbCom.SelectedItem.ToString(); // Gán PortName bằng COM đã chọn }
private void btNgat_Click(object sender, EventArgs e) { if (Serial_port.IsOpen) { Serial_port.Close(); groupBox1.Enabled = true; } }
private void btn_stop_Click(object sender, EventArgs e) { if (Serial_port.IsOpen) { Serial_port.Close(); groupBox1.Enabled = true; gb_managament.Enabled = false; } }
private void cbStop_SelectedIndexChanged(object sender, EventArgs e) { if (Serial_port.IsOpen) { Serial_port.Close(); } switch (cbStop.SelectedItem.ToString()) { case "1": Serial_port.StopBits = StopBits.One; break; case "1.5": Serial_port.StopBits = StopBits.OnePointFive; break; case "2": Serial_port.StopBits = StopBits.Two; break; } }
private void cbParity_SelectedIndexChanged(object sender, EventArgs e) { if (Serial_port.IsOpen) { Serial_port.Close(); } switch (cbParity.SelectedItem.ToString()) { case "Odd": Serial_port.Parity = Parity.Odd; break; case "None": Serial_port.Parity = Parity.None; break; case "Even": Serial_port.Parity = Parity.Even; break; } }