Sunteți pe pagina 1din 3

using

using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;
System.Threading;

namespace winproyUART
{
public partial class Form1 : Form
{
Thread hebrita;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
hebrita = new Thread(enviando);
hebrita.Start();
}
private void enviando()
{
//Normalemente ira en button1_clik pero se pone en 'enviando' para poder usar
hebras

puerto.Write(textBox1.Text); //Escribe en el bufer del serialPort


MessageBox.Show("Termin de enviarse");

private void Form1_Load(object sender, EventArgs e)


{
puerto.Open();
puerto.BaudRate = 100; //1Baut = 1 bit Por segundo

}
private void button2_Click(object sender, EventArgs e)
{
textBox2.Text = puerto.BytesToWrite.ToString();
//hebras: flujos de ejecusin : 0para instrucciones paralelas
}
}

using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;

namespace winProyUART2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnBytesRex_Click(object sender, EventArgs e)
{
txtBytesRex.Text = puerto.BytesToRead.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{

puerto.Open();
puerto.BaudRate = 100;
//cuando lleguen 20 bytes se va a disparar el evento de recepcin
puerto.ReceivedBytesThreshold = 20;

private void btnRecibir_Click(object sender, EventArgs e)


{
}
private void puerto_DataReceived(object sender,
System.IO.Ports.SerialDataReceivedEventArgs e)
{
txtMensaje.Text += puerto.ReadExisting();
MessageBox.Show("Llegaron");
}
}
}

S-ar putea să vă placă și