0% found this document useful (0 votes)
22 views2 pages

Prog PuertoSerial

Uploaded by

Daniel Gutierrez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Prog PuertoSerial

Uploaded by

Daniel Gutierrez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
// Para el puerto Serial:
using System.IO.Ports;

namespace PuertoSerial
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();

for (int i = 1; i <= 20; i++)


{
comboPuerto.Items.Add("COM" + i.ToString());
}
comboPuerto.Text = "COM1";
}

private void botonIniciar_Click(object sender, EventArgs e)


{
puertoSerial.PortName = comboPuerto.Text;
puertoSerial.BaudRate = 9600;
puertoSerial.DataBits = 8;
puertoSerial.Parity = Parity.None;
puertoSerial.StopBits = StopBits.One;

// Abrir el puerto:
if (puertoSerial != null)
{
puertoSerial.Open();
MessageBox.Show("Puerto abierto");
timer1.Interval = 200;
timer1.Enabled = true;
}
}

private void botonEnviar_Click(object sender, EventArgs e)


{
//puertoSerial.Write(cajaEnviar.Text);
puertoSerial.WriteLine(cajaEnviar.Text);
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)


{
// Si el usuario cierra la aplicaci�n, cerramos el puerto serial:
if (puertoSerial != null)
{
if (puertoSerial.IsOpen == true)
{
timer1.Enabled = false;
puertoSerial.Close();
MessageBox.Show("Puerto cerrado");
}
}
}

private void botonRecibir_Click(object sender, EventArgs e)


{
cajaRecibir.Text = puertoSerial.ReadExisting();
}

private void timer1_Tick(object sender, EventArgs e)


{
cajaRecibir.Text = puertoSerial.ReadExisting();
}
}
}

You might also like