private void BtnEnviarDatos_Click(object sender, EventArgs e) { try { SpPuertos.DiscardOutBuffer(); //byte[] buffer_out = new byte[30]; var pruebas = strinToByte(TxtEnviar.Text); //var prueba2 = Convert.ToDecimal(TxtEnviar.Text); // byte[] arreglo = { 0x1D, 0x49 , 0x40}; // byte[] arreglo2 = { 0x1F, 0x74 }; byte[] arreglo2 = { 0x1B, 0x6D }; //buffer_out[1] = 0xbb; // int offset = 0; if (SpPuertos.IsOpen == true) { //MessageBox.Show("Esta Abierto"); SpPuertos.WriteLine(""); SpPuertos.WriteLine(""); SpPuertos.WriteLine("meper d0nas¿ si te e fayado t pido perdon d la única forma q c dandote mi corason para kuando decidas volver, yo solo quiero tu amistad"); //SpPuertos.WriteLine("compañeros de oficina porfavor :) de antemano gracias"); SpPuertos.WriteLine(""); SpPuertos.WriteLine(""); SpPuertos.WriteLine(""); SpPuertos.WriteLine(""); SpPuertos.WriteLine(""); SpPuertos.WriteLine(""); SpPuertos.Write(arreglo2, 0, arreglo2.Length); // SpPuertos.Read(arreglo, offset, arreglo.Length); } else { MessageBox.Show("Esta Cerrado"); } SpPuertos.Close(); MessageBox.Show("Funciono?"); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } }
private void BotAbrirPuerto_Click(object sender, EventArgs e) // Al hacer click sobre el boton de abrir puerto { try // en el caso de no haber error { if (BotAbrirPuerto.Text == "ABRIR") // se el puerto estaba cerrado { SpPuertos.BaudRate = Int32.Parse(comboBaudRate.Text); // toma el BaudRate definido SpPuertos.DataBits = 8; // fija los bits del dato en 8 SpPuertos.Parity = Parity.None; // define datos sin paridad SpPuertos.StopBits = StopBits.One; // define un bit de parada SpPuertos.Handshake = Handshake.None; SpPuertos.PortName = ComboPuertos.Text; // guarda el nombre del puerto try { SpPuertos.Open(); // abre el puerto BotAbrirPuerto.Text = "CERRAR"; // modifica el texto del boton a "cerrar" } catch (Exception exc) // al producirse un error dispone el mensaje pertinente { MessageBox.Show(exc.Message.ToString()); } } else if (BotAbrirPuerto.Text == "CERRAR") // si el puerto estaba abierto, se cierra el puerto y cambia el texto del boton { SpPuertos.Close(); BotAbrirPuerto.Text = "ABRIR"; } } catch (Exception exc) // se dispone un mensaje ante cualquier error { MessageBox.Show(exc.Message.ToString()); } }
private void FormROV_FormClosing(object sender, FormClosingEventArgs e) { if (SpPuertos.IsOpen) { DialogResult dialogo = MessageBox.Show("¿Desea salir de Settings ROV?\nSi cierra la ventana se cerraran todos los puertos.", "Puertos Abiertos", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (dialogo == DialogResult.OK) { } else { SpPuertos.Close(); btnConectar.Text = "Conectar"; e.Cancel = true; } } else { SpPuertos.Close(); } }
private void BtnConectar_Click(object sender, EventArgs e) { try { //'CONECTAR' configura el puerto, lo abre, cambia a 'DESCONECTAR' y habilita el botón 'Enviar Datos' if (BtnConectar.Text == "CONECTAR") { SpPuertos.BaudRate = Int32.Parse(CboBaudRate.Text); SpPuertos.DataBits = 8; SpPuertos.Parity = Parity.None; SpPuertos.StopBits = StopBits.One; SpPuertos.Handshake = Handshake.None; SpPuertos.PortName = CboPuertos.Text; try { SpPuertos.Open(); BtnConectar.Text = "DESCONECTAR"; BtnEnviarDatos.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } //'DESCONECTAR' cierra el puerto, cambia a 'CONECTAR' y desabilita el botón 'Enviar Datos' else if (BtnConectar.Text == "DESCONECTAR") { SpPuertos.Close(); BtnConectar.Text = "CONECTAR"; BtnEnviarDatos.Enabled = false; } } catch (Exception ex) { //Si hay algún problema conectándose se muestra por pantalla el error MessageBox.Show(ex.Message.ToString()); } }
private void btnConectar_Click(object sender, EventArgs e) { try { if (btnConectar.Text == "Conectar") { SpPuertos.BaudRate = Convert.ToInt32(cbxBaudrate.Text); SpPuertos.DataBits = 8; SpPuertos.Parity = Parity.None; SpPuertos.StopBits = StopBits.One; SpPuertos.Handshake = Handshake.None; SpPuertos.PortName = cbxPorts.Text.ToString(); try { SpPuertos.Open(); tsStatusCOM.Visible = true; tsStatusCOM.Text = " '" + cbxPorts.SelectedItem.ToString() + "' Seleccionado."; btnConectar.Text = "Desconectar"; } catch (Exception exc) { MessageBox.Show(exc.Message.ToString());; } } else if (btnConectar.Text == "Desconectar") { SpPuertos.Close(); listBox1.Items.Clear(); tsStatusCOM.Visible = false; btnConectar.Text = "Conectar"; } } catch (Exception exc) { MessageBox.Show(exc.Message.ToString()); } }
private void button2_Click(object sender, EventArgs e) { try { if (BtnConectar.Text == "CONECTAR") { SpPuertos.BaudRate = Int32.Parse(CboBaudRate.Text); SpPuertos.DataBits = 8; SpPuertos.Parity = Parity.None; SpPuertos.StopBits = StopBits.One; SpPuertos.Handshake = Handshake.None; SpPuertos.PortName = CboPuertos.Text; try { SpPuertos.Open(); BtnConectar.Text = "DESCONECTAR"; BtnEnviarDatos.Enabled = true; } catch (Exception exc) { MessageBox.Show(exc.Message.ToString()); } } else if (BtnConectar.Text == "DESCONECTAR") { SpPuertos.Close(); BtnConectar.Text = "CONECTAR"; BtnEnviarDatos.Enabled = false; } } catch (Exception exc) { MessageBox.Show(exc.Message.ToString()); } }
private void BtnConectar_Click(object sender, EventArgs e) { try { if (BtnConectar.Text == "Conectar") { SpPuertos.BaudRate = 115200; SpPuertos.DataBits = 8; SpPuertos.Parity = Parity.None; SpPuertos.StopBits = StopBits.One; SpPuertos.Handshake = Handshake.None; SpPuertos.PortName = CboPuertos.Text; try { SpPuertos.Open(); BtnConectar.Text = "Desconectar"; BtnEnviarDatos.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } else if (BtnConectar.Text == "Desconectar") { SpPuertos.Close(); BtnConectar.Text = "Desconectar"; BtnEnviarDatos.Enabled = false; } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } }