If it's really a Permission denied exception, then it looks to me like 
you might need root rights.
Thats a standard requirement on raw ports anyway.

Am 13.03.2011 23:31, schrieb Mrhyde88:
> Hi guys
>
> im just starting with Mono on linux, and im having problems getting the
> serial port to work, heres the code im using:
>
> ##########################################################
> using System;
> using Gtk;
> using System.IO.Ports;
>
>
>
> public partial class MainWindow : Gtk.Window
> {
>       SerialPort sport= new System.IO.Ports.SerialPort("/dev/ttyS0", 9600,
> Parity.None,8, StopBits.None);
>       public MainWindow () : base(Gtk.WindowType.Toplevel)
>       {
>               Build ();
>               
>               
>       }
>
>       protected void OnDeleteEvent (object sender, DeleteEventArgs a)
>       {
>               Application.Quit ();
>               a.RetVal = true;
>       }
>       
>       //initialize serial port
>       public void serial(){
>       //SerialPort sport= new System.IO.Ports.SerialPort("/dev/ttyUSB0", 
> 9600);
>       
>       if (sport.IsOpen==false){
>               sport.BaudRate=9600;
>               sport.DtrEnable=true;
>               sport.RtsEnable=true;
>               sport.Open();
>               sport.ReadTimeout=400;
>               }
>       else
>       {
>               sport.Close();  
>       }
>               
>       
>       }
>       
>       //read serial port Data
>       public string ReadData()
>       {
>               byte tmpByte;
>               string rxString = "";
>               
>               tmpByte = (byte) sport.ReadByte();
>
>               while (tmpByte != 255)
>               {
>                       rxString += ((char) tmpByte);
>               
>                       tmpByte = (byte) sport.ReadByte();                      
>               }
>       
>               return rxString;
>       }
>
>       protected virtual void OnBtnimagePressed (object sender, 
> System.EventArgs
> e)
>       {
>               serial();
>               txtserial.Text= ReadData();
>               
>       }
>       
>       
>       
>       
> }
>
> ####################
>
> The program crashes on the sport.Open() instruction,
>
> System.Reflection.TargetInvocationException: Exception has been thrown by
> the target of an invocation. --->  System.IO.IOException: Permission denied
>
>
> Regards
>
>
> --
> View this message in context: 
> http://mono.1490590.n4.nabble.com/linux-Serial-Port-tp3352705p3352705.html
> Sent from the Mono - Dev mailing list archive at Nabble.com.
> _______________________________________________
> Mono-devel-list mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/mono-devel-list

_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to