private void btnIniciar_Click(object sender, EventArgs e) { if (pos1 & pos2) { try { SerialPort1.Write("1"); Thread.Sleep(3770); CualAdelanto(Letra); Milisegundos1.Start(); Milisegundos2.Start(); btnIniciar.Enabled = false; btnPosicion.Enabled = false; btnFinalizar.Enabled = true; } catch (Exception ex) { throw ex; } } else { MessageBox.Show("Ocurrio un error: " + Environment.NewLine + "Hay un coche en posición incorrecta", "Autodromo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void SerialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) { try { dato = SerialPort1.ReadExisting().Trim(); if (dato.Contains("ll1")) { Milisegundos1.Stop(); llego1 = true; } else if (dato.Contains("ll2")) { Milisegundos2.Stop(); llego2 = true; } else if (dato.Contains("11")) { pbRojo1.Visible = false; pos1 = true; pbRojo2.Visible = false; pos2 = true; } else if (dato.Contains("10")) { pbRojo1.Visible = false; pos1 = true; pbRojo2.Visible = true; pos2 = false; } else if (dato.Contains("01")) { pbRojo1.Visible = true; pos1 = false; pbRojo2.Visible = false; pos2 = true; } else if (dato.Contains("00")) { pbRojo1.Visible = true; pos1 = false; pbRojo2.Visible = true; pos2 = false; } else if (dato.Contains("A")) { Letra = dato; } else if (dato.Contains("B")) { Letra = dato; } else if (dato.Contains("C")) { Letra = dato; } else if (dato.Contains("D")) { Letra = dato; } dato = ""; } catch (Exception ex) { MessageBox.Show(ex.Message); } }