/*---Car IN---*/ void Car_in(string in_location, string in_maso, string in_time, string in_date) // đưa xe vào với vị trí, mã thẻ, thời gian, ngày { try { if (IsNumber(in_location) && Convert.ToInt32(in_location) <= 6 && Convert.ToInt32(in_location) > 0 && done == true) { if (check_in_car(in_location) == true && check_ID_car_in(in_maso) == true) { if (Admin_test == false) { Serial_port.Write("E0"); // OKE } else { Admin_test = false; } lb_error.Text = "Complete"; txt_vitri.Text = in_location; txt_maso.Text = in_maso; txt_time.Text = in_time; txt_date.Text = in_date; done = false; pic_car.Visible = true; Set_status(true, in_location); Set_ID_card_time(in_maso, in_time, in_date, in_location); Timer_1.Start(); } else { if (check_in_car(in_location) == false) { Serial_port.Write("E3"); // Chưa đồng bộ dữ liệu lb_error.Text = "Upload"; } else if (check_ID_car_in(in_maso) == false) { Serial_port.Write("E2"); // Thẻ đã được xử dụng lb_error.Text = "Used card"; } } } else { lb_error.Text = "Upload"; Serial_port.Write("E3"); // Chưa đồng bộ dữ liệu } } catch { lb_error.Text = "Error"; if (Serial_port.IsOpen) { Serial_port.Write("E4"); //Có lỗi xảy ra } else { MessageBox.Show("Chưa mở cổng COM"); } } }
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 Serial_port_DataReceived(object sender, SerialDataReceivedEventArgs e) { serialPortReceiverAction = serialPortReceiver; try { this.BeginInvoke(serialPortReceiverAction, Serial_port.ReadExisting()); } catch { } }
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 btn_send_Click(object sender, EventArgs e) { if (Serial_port.IsOpen) { Serial_port.Write(txt_send.Text); } else { MessageBox.Show("Chưa mở cổng COM", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Hand); } }
private void btn_led_3_Click(object sender, EventArgs e) { if (Serial_port.IsOpen) { Serial_port.Write("3"); } else { MessageBox.Show("Chưa mở cổng COM"); } }
private void btKetnoi_Click(object sender, EventArgs e) { try { Serial_port.Open(); groupBox1.Enabled = false; } catch { MessageBox.Show("Không thể mở công COM"); } }
/*---Car OUT---*/ void Car_out(string out_location) // lấy xe ra với vị trí với mã thẻ { try { if (IsNumber(out_location) && Convert.ToInt32(out_location) <= 6 && Convert.ToInt32(out_location) > 0 && done == true) { if (check_out_car(out_location) == true) { if (Admin_test == false) { Serial_port.Write("E0"); // OKE } else { Admin_test = false; } lb_error.Text = "Complete"; done = false; txt_vitri.Text = out_location; Set_status(false, out_location); Set_ID_card_time("", "", "", out_location); Timer_4.Start(); } else { MessageBox.Show("Chưa có xe tại vị trí đó", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { Serial_port.Write("E5"); // Thẻ chưa đc xử dụng lb_error.Text = "Card error"; } } catch { lb_error.Text = "Error"; if (Serial_port.IsOpen) { Serial_port.Write("E4"); //Có lỗi xảy ra } else { MessageBox.Show("Chưa mở cổng COM"); } } }
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; } }