private void button1_Click(object sender, EventArgs e) { //Si hay un item seleccionado y la caja de texto no esta vacia if (this.comboBox2.SelectedItem != null & this.textBox1.Text != "") { //Se obtiene el nombre del puerto del combobox 'puerto serie' Program.nombrePuerto = this.comboBox2.SelectedItem.ToString(); //Se obtiene la velocidad del puerto Program.velocidadPuerto = int.Parse(this.textBox1.Text); //Se establece el nombre del puerto this.serialPort1.PortName = this.comboBox2.SelectedItem.ToString(); //Se establece la velocidad del puerto serie this.serialPort1.BaudRate = int.Parse(textBox1.Text); this.serialPort1.ReadBufferSize = 40000; //Se abre el puerto serie this.serialPort1.Open(); while (!this.serialPort1.IsOpen) { this.serialPort1.Open(); } this.serialPort1.ReadExisting(); this.serialPort1.WriteLine("c"); //se envia una c para confirmar que se está en modo configuración //Mientras bytes a leer sea 0 while (this.serialPort1.ReadByte() != (int)'c') { this.serialPort1.WriteLine("c"); } Thread.Sleep(1000); //Si el combobox 'velocidad CAMBUS' es distinto cadena vacia y comprueba es distinto de caracter 0 if (comboBox1.Text != "" & this.comprueba() != (char)0) { byte[] auxiliar = new byte[2]; byte var = 50;//Hay que revisar this.serialPort1.ReadExisting(); this.serialPort1.WriteLine("2"); int b1 = this.serialPort1.ReadByte(); while (b1 != var) { this.serialPort1.Write("2"); b1 = this.serialPort1.ReadByte(); } this.serialPort1.ReadExisting(); this.serialPort1.WriteLine(comprueba().ToString()); int b = this.serialPort1.ReadByte(); while (b != (int)comprueba()) { this.serialPort1.WriteLine(comprueba().ToString()); b = this.serialPort1.ReadByte(); } this.serialPort1.ReadExisting(); this.Close(); CConfig.configuracion.configuracion[0].velocidad = this.comboBox1.Text; CConfig.configuracion.configuracion[0].tipo = grabaTipoMensaje(); CConfig.configuracion.configuracion[0].velocidadPuerto = this.textBox1.Text; CConfig.configuracion.configuracion[0].nombrePuerto = this.comboBox2.Text; CConfig.grabar(); } } else { MessageBox.Show("Introduzca los datos necesarios para la configuración", "INFORMACIÓN"); } }