Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/12/2008, 21:13
REHome
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 17 años
Puntos: 8
Respuesta: PAsar de Windows a Linux

He logrado ya por fin ejecutar el código sin problemas, pero hay otro problema al pulsar cualquier botón.

Al ejecutar desde la consola de Linux se ejecuta muy bien, pero al pulsar el botón del formulario principal de la aplicación se me cierra y me dice este error.

Cita:
metaconta@dhcppc2:~/Prueba3/Prueba3/bin/Debug> mono Prueba3.exe
Exception in Gtk# callback delegate
Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.InvalidOperationException: Specified port is not open.
at System.IO.Ports.SerialPort.CheckOpen () [0x00000]
at System.IO.Ports.SerialPort.Write (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000]
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Write (byte[],int,int)
at MainWindow.OnButtonTClicked (System.Object sender, System.EventArgs e) [0x00000]
at GLib.Signal.voidObjectCallback (IntPtr handle, IntPtr data) [0x00000]
at GLib.ExceptionManager.RaiseUnhandledException(Syst em.Exception e, Boolean is_terminal)
at GLib.Signal.voidObjectCallback(IntPtr handle, IntPtr data)
at GLib.Signal.voidObjectCallback(IntPtr , IntPtr )
at Gtk.Application.gtk_main()
at Gtk.Application.gtk_main()
at Gtk.Application.Run()
at Prueba3.MainClass.Main(System.String[] args)
El código es nuevo es:
Cita:
// MainWindow.cs created with MonoDevelop
// User: metaconta at 23:01 08/12/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
using System;
using Gtk;
using System.IO.Ports; // Añadir este using.

public partial class MainWindow: Gtk.Window
{
private SerialPort miSerie; // miSerie.

public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
//serialPort1 = new SerialPort("/dev/ttyS0",9600, Parity.None, 8, StopBits.Two);
miSerie = new SerialPort("/dev/ttyS0",9600, Parity.None, 8, StopBits.Two);

// Abrir puerto mientra se ejecute la aplicación
if (!miSerie.IsOpen)
{
try
{
miSerie.Open();
}
catch (System.Exception ex)
{
// MessageBox.Show(ex.ToString());
// label1.Text = ex.ToString();
entry1.Text = ex.ToString();
}
}
}

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".
miSerie.Write(mBuffer, 0, mBuffer.Length);
}

protected virtual void OnButtonBClicked (object sender, System.EventArgs e)
{
byte[] miBuffer = new byte[1];
miBuffer[0] = 0x62; //ASCII letra "b".
miSerie.Write(miBuffer, 0, miBuffer.Length);
}

protected virtual void OnButtonAClicked (object sender, System.EventArgs e)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x61; //ASCII letra "a".
miSerie.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".
miSerie.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".
miSerie.Write(mBuffer, 0, mBuffer.Length);
}
}
__________________
Meta Shell, VERSIÓN 1.2.2
Descargar