Utilizando el MonoDevelop en Linux, creé en gtk# un proyecto, coloqué sólo un botón en el formulario. Sólo quiero abrir el puerto serie y enviar un byte al puerto serie.
El código completo hasta ahora es:
Código:
// 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(); } }
Al ejecutar se ejecuta sin problemas, pero lo hay al pulsar el botón y me muestra este menaje de errores o algo parecido y no envía nada al puerto serie y quiero resolver este problema.
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.P orts.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(Syst em.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