
24/02/2009, 17:40
|
| | Fecha de Ingreso: mayo-2007 Ubicación: PIC-16F84A
Mensajes: 729
Antigüedad: 17 años, 8 meses Puntos: 8 | |
Respuesta: invoke Funciona ese metodo que me dijiste y gracias.
Ahora, no me lee la entrada de datos en un textBox, label, etc... que sea algo que lea los mensajes desde el PIC.
Código:
// MainWindow.cs created with MonoDevelop
// User: metaconta at 17:10*24/02/2009
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
using System;
using Gtk;
using System.IO.Ports;
using System.ComponentModel;
public partial class MainWindow: Gtk.Window
{
private SerialPort mySerial;
// Utilizaremos un string como Buffer de recepción.
string Recibidos;
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
mySerial = new SerialPort("/dev/ttyS0", 9600, Parity.None, 8, StopBits.Two);
if (!mySerial.IsOpen)
{
try
{
mySerial.Open();
}
catch (System.Exception ex)
{
label1.Visible = true;
label1.Text = ex.ToString();
}
}
// Ejecutar la función Recepcion por disparo de evento DataReived.
mySerial.DataReceived += new SerialDataReceivedEventHandler(Recepcion);
}
// Al recibir los datos.
private void Recepcion(object sender, SerialDataReceivedEventArgs e)
{
// Acumular los carácter recibidos a nuestro "buffer" (string).
Recibidos += mySerial.ReadExisting();
// Invocar o llamar el proceso de tramas.
Gtk.Application.Invoke(new EventHandler(Actualizar));
}
// Procesar los daros recibidos en el buffer y extraer tramas completas.
private void Actualizar(object s, EventArgs e)
{
// Designar el valor de la trama textBox.
//textview_visualizar_mensaje.Text = Recibidos;
entry_visualizar_mensaje.Text = Recibidos;
label2.Text = Recibidos;
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
protected virtual void OnButtonTClicked (object sender, System.EventArgs e)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x74; // ASCII letra t.
mySerial.Write(mBuffer, 0, mBuffer.Length);
}
protected virtual void OnButtonBClicked (object sender, System.EventArgs e)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x62; // ASCII letra b.
mySerial.Write(mBuffer, 0, mBuffer.Length);
}
protected virtual void OnButtonAClicked (object sender, System.EventArgs e)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x61; // ASCII letra a.
mySerial.Write(mBuffer, 0, mBuffer.Length);
}
protected virtual void OnButtonLClicked (object sender, System.EventArgs e)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x6C; // ASCII letra l.
mySerial.Write(mBuffer, 0, mBuffer.Length);
}
protected virtual void OnButtonEspacioClicked (object sender, System.EventArgs e)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x20; // ASCII letra Espacio.
mySerial.Write(mBuffer, 0, mBuffer.Length);
}
}
Precisamente los datos que deseo que se vea los textos desde el PIC qu esean un textBox o algo que se le parezca, el programa funciona bien pero no muestra los datos como un HyperTerminal de Windows.
Código:
// Procesar los daros recibidos en el buffer y extraer tramas completas.
private void Actualizar(object s, EventArgs e)
{
// Designar el valor de la trama textBox.
//textview_visualizar_mensaje.Text = Recibidos;
entry_visualizar_mensaje.Text = Recibidos;
label2.Text = Recibidos;
}
__________________ Meta Shell, VERSIÓN 1.2.2 Descargar |