Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - Meta

#1961
Hola:

Estoy haciendo la continuación del manual sobre Visual C# de la parte de MonoDevelop 1 bajo Linux, por otro lado algo de Visual C++ y Visual Basic.

El único código funcional es el VC++, el VB funciona aunque no está publicado porque está hecho a la chapuza. Cuando lo haga seriamente lo publico en el manual. Si alguien quiere ese código ya, me lo dicen y lo pongo aquí, funciona, pero no es el adecuado, hay otro método que estoy averiguando en hacerlo más cómodo y con menos código.

El manual no está acabado, sólo verán su estilo a ver si les gusta y yo mismo ver sus sugerencias.

DESCARGAR Manual PDF

Un cordial saludo.
#1962
Cita de: JuanK_Solocodigo en 25 Febrero 2009, 20:56 PM
en el evento Closed o Closing del programa llama a la función que maneja el otro evento que dices...


oops bueno... si es el mismo programa que pusiste en msdn estas en windows forms supongo...


saludos...  ::)

Me funciona, gracias.
#1963
Hola:

Tengo un código hecho con Visual C#  Express. Se trata de que uso el puerto serie, si pulso un botón dejo la comunicación activa, si cierro el programa principal, el dato enviado por el puerto serie que lleva hasta un PIC16F84A está activo, antes de cerrar el programa debo pulsar el otro botón para desactivar el PIC por el puerto serie. Me gustaría saber si hay una posibilidad de que se cuando cierre la aplicación, envíe un comando del mismo botón que hace que se desactive el PIC. Espero averiguar o al menos saber si existe hacer esa posibilidad.

Código (csharp) [Seleccionar]
            byte[] mBuffer = new byte[1];
            mBuffer[0] = 0x20; //ASCII letra "Espacio".
            serialPort1.Write(mBuffer, 0, mBuffer.Length);


Un cordial saludo.
#1964
.NET (C#, VB.NET, ASP) / Re: Puerto serie RS232
23 Febrero 2009, 23:33 PM
Vamos a empezar desde el principio.

Utilizando el Mono con gtk#, he introducido un botón normal en el formulario. El código completo lo he hecho de nuevo y ahora es así. Ejecuta sin problemas pero al pulsar el botón hay errores que no se el motivo.

Código (csharp) [Seleccionar]

// MainWindow.cs created with MonoDevelop
// User: metaconta at 20:59 23/02/2009
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
using System;
using Gtk;
using System.IO.Ports;

public partial class MainWindow: Gtk.Window
{
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
}

protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}

public SerialPort mySerial;

protected virtual void OnButtonTClicked (object sender, System.EventArgs e)
{
mySerial = new SerialPort("/dev/ttyS0", 9600, Parity.None, 8, StopBits.Two);
mySerial.Open();
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x74; // LA letra t.
mySerial.Write(mBuffer, 0, mBuffer.Length);
mySerial.Close();
}
}


En el mensaje de error me da esto:
Código (csharp) [Seleccionar]


Marshaling clicked signal
Exception in Gtk# callback delegate
  Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.IOException: Permiso denegado
  at System.IO.Ports.SerialPortStream.ThrowIOException () [0x00012] in /usr/src/packages/BUILD/mono-2.0.1/mcs/class/System/System.IO.Ports/SerialPortStream.cs:299
  at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x0001e] in /usr/src/packages/BUILD/mono-2.0.1/mcs/class/System/System.IO.Ports/SerialPortStream.cs:36
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
  at System.IO.Ports.SerialPort.Open () [0x00078] in /usr/src/packages/BUILD/mono-2.0.1/mcs/class/System/System.IO.Ports/SerialPort.cs:563
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
  at MainWindow.OnButtonTClicked (System.Object sender, System.EventArgs e) [0x00018] in /home/metaconta/Prueba_02/Prueba_02/MainWindow.cs:28
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00057] in /usr/src/packages/BUILD/mono-2.0.1/mcs/class/corlib/System.Reflection/MonoMethod.cs:157
  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00071] in /usr/src/packages/BUILD/mono-2.0.1/mcs/class/corlib/System.Reflection/MonoMethod.cs:167
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /usr/src/packages/BUILD/mono-2.0.1/mcs/class/corlib/System.Reflection/MethodBase.cs:110
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000b4] in /usr/src/packages/BUILD/mono-2.0.1/mcs/class/corlib/System/Delegate.cs:422
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00018] in /usr/src/packages/BUILD/mono-2.0.1/mcs/class/corlib/System/MulticastDelegate.cs:71
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in /usr/src/packages/BUILD/mono-2.0.1/mcs/class/corlib/System/Delegate.cs:394
  at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x0004f] in /usr/src/packages/BUILD/gtk-sharp-2.12.6/glib/Signal.cs:195
  at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x0000c] in /usr/src/packages/BUILD/gtk-sharp-2.12.6/glib/SignalClosure.cs:118
  at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x0007a] in /usr/src/packages/BUILD/gtk-sharp-2.12.6/glib/SignalClosure.cs:146
   at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e, Boolean is_terminal) in /usr/src/packages/BUILD/gtk-sharp-2.12.6/glib/ExceptionManager.cs:line 58
   at GLib.SignalClosure.MarshalCallback(IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) in /usr/src/packages/BUILD/gtk-sharp-2.12.6/glib/SignalClosure.cs:line 173
   at Gtk.Application.gtk_main()
   at Gtk.Application.Run() in /usr/src/packages/BUILD/gtk-sharp-2.12.6/gtk/generated/AboutDialog.cs:line 1
   at Prueba_02.MainClass.Main(System.String[] args) in /home/metaconta/Prueba_02/Prueba_02/Main.cs:line 18


#1965
.NET (C#, VB.NET, ASP) / Puerto serie RS232
23 Febrero 2009, 21:39 PM
Hola:

Estoy con MonoDevelop con el openSUSE 11.1. Mirando esta web http://www.mono-project.com/HowToSystemIOPorts quiero configurar el puerto serie como a mi me de la gana.

Lo he puesto así:

Código (csharp) [Seleccionar]
mySerial new SerialPort("/dev/ttyS0", 9600, None, 8, Two);

La otra manera con comillas así:

Código (csharp) [Seleccionar]
mySerial new SerialPort("/dev/ttyS0", 9600, "None", 8, "Two");

Código completo:

Código (csharp) [Seleccionar]
// MainWindow.cs created with MonoDevelop
// User: metaconta at 17:46 23/02/2009
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
using System;
using Gtk;
using System.IO.Ports;

public partial class MainWindow: Gtk.Window
{
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
}

protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}

protected virtual void OnButton1Clicked (object sender, System.EventArgs e)
{
mySerial new SerialPort("/dev/ttyS0", 9600, None, 8, Two);
}
}


Me da error en la línea 25. ¿Qué puede ser?

Estoy intentando pasar este código de Visual C# a Mono, puedes ver el código en las páginas 153 y 154 en este manual en PDF.

http://www.abcdatos.com/tutoriales/tutorial/z9521.html

Saludos.

EDITO:
He logrado abrir el puerto pero no he sido enviar el código al puerto serie.
Código (csharp) [Seleccionar]

// MainWindow.cs created with MonoDevelop
// User: metaconta at 17:46 23/02/2009
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
using System;
using Gtk;
using System.IO.Ports;

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

public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
}

protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}

protected virtual void OnButton1Clicked (object sender, System.EventArgs e)
{
mySerial = new SerialPort("/dev/ttyS0", 9600, Parity.None, 8, StopBits.Two);

if(mySerial == null) return;

mySerial.Open();

if(!mySerial.IsOpen)
{
label1.Text = "Error abriendo";
mySerial.Dispose();
return;
}

byte[] buffer = new byte[1];
buffer[0] = 0x74;
mySerial.Write(buffer, 0, 1);

try
{
mySerial.Write(buffer, 0, 1);
}
catch(Exception ex)
{
//label1.Text = ex.Message;// + " " + ex.StackTrace;
mySerial.Close();
mySerial.Dispose();
return;
}

mySerial.Close();
}
}


Un cordial saludo.
#1966
Hola:

Intentando pasar de VC# a VC++ esta parte que parece que no sirve.

Código (csharp) [Seleccionar]
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.IO.Ports;
10
11 namespace PicRS232
12 {
13     public partial class Form1_Principal : Form
14     {
15         // Utilizaremos un string como buffer de recepcion
16         string Recibidos;
17         public Form1_Principal()
18         {
19             InitializeComponent();
20             // Abrir puerto mientra se ejecute la aplicación
21             if (!serialPort1.IsOpen)
22             {
23                 try
24                 {
25                     serialPort1.Open();
26                 }
27                 catch (System.Exception ex)
28                 {
29                     MessageBox.Show(ex.ToString());
30                 }
31             }
32             // Ejecutar la funcion Recepcion por disparo del Evento 'DataReived'
33             serialPort1.DataReceived += new
34             System.IO.Ports.SerialDataReceivedEventHandler(Recepcion);
35         }
36         // Al recibir los datos
37         private void Recepcion(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
38         {
39             // Acumular los carácteres recibidos a nuestro 'buffer' (string)
40             Recibidos += serialPort1.ReadExisting();
41             // Invocar o llamar al proceso de tramas
42             this.Invoke(new EventHandler(Actualizar));
43         }
44         // Procesar los datos recibidos en el buffer y extraer tramas completas
45         private void Actualizar(object s, EventArgs e)
46         {
47             // Asignar el valor de la trama al textBox
48             textBox_visualizar_mensaje.Text = Recibidos;
49         }
50         private void button_t_Click(object sender, EventArgs e)
51         {
52             byte[] mBuffer = new byte[1];
53             mBuffer[0] = 0x74; //ASCII letra "t".
54             serialPort1.Write(mBuffer, 0, mBuffer.Length);
55         }
56
57         private void button_b_Click(object sender, EventArgs e)
58         {
59             byte[] miBuffer = new byte[1];
60             miBuffer[0] = 0x62; //ASCII letra "b".
61             serialPort1.Write(miBuffer, 0, miBuffer.Length);
62         }
63
64         private void button_a_Click(object sender, EventArgs e)
65         {
66             byte[] mBuffer = new byte[1];
67             mBuffer[0] = 0x61; //ASCII letra "a".
68             serialPort1.Write(mBuffer, 0, mBuffer.Length);
69         }
70
71         private void button_l_Click(object sender, EventArgs e)
72         {
73             byte[] mBuffer = new byte[1];
74             mBuffer[0] = 0x6C; //ASCII letra "l".
75             serialPort1.Write(mBuffer, 0, mBuffer.Length);
76         }
77
78         private void button_Espacio_Click(object sender, EventArgs e)
79         {
80             byte[] mBuffer = new byte[1];
81             mBuffer[0] = 0x20; //ASCII letra "Espacio".
82             serialPort1.Write(mBuffer, 0, mBuffer.Length);
83         }
84
85         private void timer1_Tick(object sender, EventArgs e)
86         {
87             statusStrip1.Items[0].Text = DateTime.Now.ToLongTimeString();
88         }
89     }
90 }


Código completo de Visual C# Express. Descargar aquí.

Por ahora he hecho el código en Visual C++ pero me faltan hacer cosas que no he incuido.
Código (cpp) [Seleccionar]

1 #pragma once
2
3
4 namespace PicRS232VCPP_Prueba01 {
5
6     using namespace System;
7     using namespace System::ComponentModel;
8     using namespace System::Collections;
9     using namespace System::Windows::Forms;
10     using namespace System::Data;
11     using namespace System::Drawing;
12     using namespace System::IO::Ports;
13
14     /// <summary>
15     /// Resumen de Form1
16     ///
17     /// ADVERTENCIA: si cambia el nombre de esta clase, deberá cambiar la
18     ///          propiedad 'Nombre de archivos de recursos' de la herramienta de compilación de recursos administrados
19     ///          asociada con todos los archivos .resx de los que depende esta clase. De lo contrario,
20     ///          los diseñadores no podrán interactuar correctamente con los
21     ///          recursos adaptados asociados con este formulario.
22     /// </summary>
23     public ref class Form1 : public System::Windows::Forms::Form
24     {
25     public:
26         Form1(void)
27         {
28             InitializeComponent();
29             //
30             //TODO: agregar código de constructor aquí
31             //
32             // Abrir puerto mientrase ejecute la aplicación
33             if(!serialPort1->IsOpen)
34             {
35                 try
36                 {
37                 serialPort1->Open();
38                 }
39                 catch (Exception ^ex)
40                 {
41                     MessageBox::Show(ex->ToString());
42                 }
43             }
44         }
45
46     protected:
47         /// <summary>
48         /// Limpiar los recursos que se estén utilizando.
49         /// </summary>
50         ~Form1()
51         {
52             if (components)
53             {
54                 delete components;
55             }
56         }
57     private: System::Windows::Forms::Button^  button_t;
58     private: System::Windows::Forms::Button^  button_b;
59     private: System::Windows::Forms::Button^  button_a;
60     private: System::Windows::Forms::Button^  button_l;
61     private: System::Windows::Forms::Button^  button_Espacio;
62     private: System::IO::Ports::SerialPort^  serialPort1;
63     private: System::ComponentModel::IContainer^  components;
64
65     protected: 
66
67     private:
68         /// <summary>
69         /// Variable del diseñador requerida.
70         /// </summary>
71
72
73 #pragma region Windows Form Designer generated code
74         /// <summary>
75         /// Método necesario para admitir el Diseñador. No se puede modificar
76         /// el contenido del método con el editor de código.
77         /// </summary>
78         void InitializeComponent(void)
79         {
80             this->components = (gcnew System::ComponentModel::Container());
81             this->button_t = (gcnew System::Windows::Forms::Button());
82             this->button_b = (gcnew System::Windows::Forms::Button());
83             this->button_a = (gcnew System::Windows::Forms::Button());
84             this->button_l = (gcnew System::Windows::Forms::Button());
85             this->button_Espacio = (gcnew System::Windows::Forms::Button());
86             this->serialPort1 = (gcnew System::IO::Ports::SerialPort(this->components));
87             this->SuspendLayout();
88             // 
89             // button_t
90             // 
91             this->button_t->Location = System::Drawing::Point(109, 38);
92             this->button_t->Name = L"button_t";
93             this->button_t->Size = System::Drawing::Size(75, 23);
94             this->button_t->TabIndex = 0;
95             this->button_t->Text = L"t";
96             this->button_t->UseVisualStyleBackColor = true;
97             this->button_t->Click += gcnew System::EventHandler(this, &Form1::button_t_Click);
98             // 
99             // button_b
100             // 
101             this->button_b->Location = System::Drawing::Point(109, 67);
102             this->button_b->Name = L"button_b";
103             this->button_b->Size = System::Drawing::Size(75, 23);
104             this->button_b->TabIndex = 1;
105             this->button_b->Text = L"b";
106             this->button_b->UseVisualStyleBackColor = true;
107             this->button_b->Click += gcnew System::EventHandler(this, &Form1::button_b_Click);
108             // 
109             // button_a
110             // 
111             this->button_a->Location = System::Drawing::Point(28, 67);
112             this->button_a->Name = L"button_a";
113             this->button_a->Size = System::Drawing::Size(75, 23);
114             this->button_a->TabIndex = 2;
115             this->button_a->Text = L"a";
116             this->button_a->UseVisualStyleBackColor = true;
117             this->button_a->Click += gcnew System::EventHandler(this, &Form1::button_a_Click);
118             // 
119             // button_l
120             // 
121             this->button_l->Location = System::Drawing::Point(190, 67);
122             this->button_l->Name = L"button_l";
123             this->button_l->Size = System::Drawing::Size(75, 23);
124             this->button_l->TabIndex = 3;
125             this->button_l->Text = L"l";
126             this->button_l->UseVisualStyleBackColor = true;
127             this->button_l->Click += gcnew System::EventHandler(this, &Form1::button_l_Click);
128             // 
129             // button_Espacio
130             // 
131             this->button_Espacio->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(255)), static_cast<System::Int32>(static_cast<System::Byte>(128)), 
132                 static_cast<System::Int32>(static_cast<System::Byte>(0)));
133             this->button_Espacio->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
134                 static_cast<System::Byte>(0)));
135             this->button_Espacio->Location = System::Drawing::Point(190, 96);
136             this->button_Espacio->Name = L"button_Espacio";
137             this->button_Espacio->Size = System::Drawing::Size(75, 23);
138             this->button_Espacio->TabIndex = 4;
139             this->button_Espacio->Text = L"Espacio";
140             this->button_Espacio->UseVisualStyleBackColor = false;
141             this->button_Espacio->Click += gcnew System::EventHandler(this, &Form1::button_Espacio_Click);
142             // 
143             // serialPort1
144             // 
145             this->serialPort1->StopBits = System::IO::Ports::StopBits::Two;
146             // 
147             // Form1
148             // 
149             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
150             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
151             this->ClientSize = System::Drawing::Size(292, 266);
152             this->Controls->Add(this->button_Espacio);
153             this->Controls->Add(this->button_l);
154             this->Controls->Add(this->button_a);
155             this->Controls->Add(this->button_b);
156             this->Controls->Add(this->button_t);
157             this->Name = L"Form1";
158             this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
159             this->Text = L"PicRS232VCPP";
160             this->ResumeLayout(false);
161
162         }
163 #pragma endregion
164     private: System::Void button_t_Click(System::Object^  sender, System::EventArgs^  e) {
165                  cli::array<unsigned char> ^uno = gcnew cli::array<unsigned char>(1);
166                  uno[0] = 0x74; //ASCII letra "t".
167                  serialPort1->Write(uno, 0, 1);
168              }
169 private: System::Void button_b_Click(System::Object^  sender, System::EventArgs^  e) {
170                  cli::array<unsigned char> ^uno = gcnew cli::array<unsigned char>(1);
171                  uno[0] = 0x62; //ASCII letra "b".
172                  serialPort1->Write(uno, 0, 1);
173          }
174 private: System::Void button_a_Click(System::Object^  sender, System::EventArgs^  e) {
175              cli::array<unsigned char> ^uno = gcnew cli::array<unsigned char>(1);
176                  uno[0] = 0x61; //ASCII letra "a".
177                  serialPort1->Write(uno, 0, 1);
178          }
179 private: System::Void button_l_Click(System::Object^  sender, System::EventArgs^  e) {
180              cli::array<unsigned char> ^uno = gcnew cli::array<unsigned char>(1);
181                  uno[0] = 0x6C; //ASCII letra "l".
182                  serialPort1->Write(uno, 0, 1);
183          }
184 private: System::Void button_Espacio_Click(System::Object^  sender, System::EventArgs^  e) {
185              cli::array<unsigned char> ^uno = gcnew cli::array<unsigned char>(1);
186                  uno[0] = 0x20; //ASCII letra "Espacio".
187                  serialPort1->Write(uno, 0, 1);
188          }
189 };
190 }
191
   


Saludos.
#1967
Electrónica / Re: chivato
5 Febrero 2009, 23:13 PM
Prueba con el puerto serie y el PIC, aunque sea el 16F84.

[youtube=425,350]http://www.youtube.com/watch?v=1sTaKKoGIqA[/youtube]

Saludos.
#1968
Si existen emuladores y enn ella lo puedes conseguir aquí y se llama Proteus.



El simulador y compilador oficial la puedes descargar en la web www.microchip.com , se llama MPLAB 8.20 en este caso que puedes descatgar aquí y es gratuito.
#1969
Las instrucciones no se llaman igual aunque hagan lo  mismo. Para el PIC es como un microprocesador pero en miniatura y es más fácil. El ASM es más potente pero está hecho para lo que está, si quieres hacer circuitos como he hecho aquí, no hay problemas.

Pon en www.youtube.com metaconta.
#1970
Donde aprendes seguro es con este  libro www.pic16f84a.org y en ese libro te enseña las bases necesarias y grbadores. Puedes leer el contenido en dicha Web, te viene con ejemplos incluidos.

IC-Prog.
http://www.abcdatos.com/tutoriales/tutorial/z9316.html

WinPic800
http://www.abcdatos.com/tutoriales/tutorial/z9157.html

Saludos.