Foros del Web » Programación para mayores de 30 ;) » .NET »

PAsar de Windows a Linux

Estas en el tema de PAsar de Windows a Linux en el foro de .NET en Foros del Web. Hola: Hice un manual para del puerto serie controlado con Visual C# .net Express 2008. Al menos hay códigos que deseo pasarlo a Linux con ...
  #1 (permalink)  
Antiguo 08/12/2008, 17:36
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 16 años, 11 meses
Puntos: 8
PAsar de Windows a Linux

Hola:

Hice un manual para del puerto serie controlado con Visual C# .net Express 2008. Al menos hay códigos que deseo pasarlo a Linux con MonoDevelop GTK# (C#).

El manual es este:
Ver manual

El código fuente al que deseo pasar a Linux es este (de la página 162 del manual):
Descargar FUENTE 1

Contraseña = D.P.E.

Si no pueden descargarlo, me avisan.

Necesito colaboradores para ampliar el manual. Por otra parte estoy pasándolo con Visual Basic y Visual C++ 2008.

Ver vídeo:
http://www.youtube.com/watch?v=niWAbQ-HVnY

Quiero que los usuarios de Windows, también entren a Linux y vean sus mismas posibilidades.

Un cordial saludo.

EDITO:

El código de Visual C# es este y quiero pasarlo a GTK# de MonoDevelop.
Código:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace PicRS232
{
    public partial class Form1_Principal : Form
    {
        public Form1_Principal()
        {
            InitializeComponent();
            // Abrir puerto mientra se ejecute la aplicación
            if (!serialPort1.IsOpen)
            {
                try
                {
                    serialPort1.Open();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }

        private void button_t_Click(object sender, EventArgs e)
        {
            byte[] mBuffer = new byte[1];
            mBuffer[0] = 0x74; //ASCII letra "t".
            serialPort1.Write(mBuffer, 0, mBuffer.Length);
        }

        private void button_b_Click(object sender, EventArgs e)
        {
            byte[] miBuffer = new byte[1];
            miBuffer[0] = 0x62; //ASCII letra "b".
            serialPort1.Write(miBuffer, 0, miBuffer.Length);
        }

        private void button_a_Click(object sender, EventArgs e)
        {
            byte[] mBuffer = new byte[1];
            mBuffer[0] = 0x61; //ASCII letra "a".
            serialPort1.Write(mBuffer, 0, mBuffer.Length);
        }

        private void button_l_Click(object sender, EventArgs e)
        {
            byte[] mBuffer = new byte[1];
            mBuffer[0] = 0x6C; //ASCII letra "l".
            serialPort1.Write(mBuffer, 0, mBuffer.Length);
        }

        private void button_Espacio_Click(object sender, EventArgs e)
        {
            byte[] mBuffer = new byte[1];
            mBuffer[0] = 0x20; //ASCII letra "Espacio".
            serialPort1.Write(mBuffer, 0, mBuffer.Length);
        }
    }
}
Dejo claro que el Visual C# uso un componente llamado serialPort1 en el que MonoDevelop no incluye. Ese es el problema que tengo. En Visual C# su configuración del componente serialPort1 está en la página 143 de este MANUAL.

Saludo.

EDITO 2:

Por ahora he lorgado esto.
Código:
// 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
{	
	public MainWindow (): base (Gtk.WindowType.Toplevel)
	{
		Build ();
		// Abrir puerto mientra se ejecute la aplicación
            if (!serialPort1.IsOpen)
            {
                try
                {
                    serialPort1.Open();
                }
                catch (System.Exception ex)
                {
                   // MessageBox.Show(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".
            serialPort1.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".
            serialPort1.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".
            serialPort1.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".
            serialPort1.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".
            serialPort1.Write(mBuffer, 0, mBuffer.Length);
	}
}
__________________
Meta Shell, VERSIÓN 1.2.2
Descargar

Última edición por REHome; 08/12/2008 a las 19:00 Razón: Añador código.
  #2 (permalink)  
Antiguo 08/12/2008, 21:13
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 16 años, 11 meses
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
  #3 (permalink)  
Antiguo 08/12/2008, 21:44
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 16 años, 11 meses
Puntos: 8
Respuesta: PAsar de Windows a Linux

Código fuente de MonoDevelop

Descargar
__________________
Meta Shell, VERSIÓN 1.2.2
Descargar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:40.