[Mono-bugs] [Bug 693370] New: SerialPort.Open() does not throw an exception if serial port is already open by another application

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu May 12 08:52:26 EDT 2011


https://bugzilla.novell.com/show_bug.cgi?id=693370

https://bugzilla.novell.com/show_bug.cgi?id=693370#c0


           Summary: SerialPort.Open() does not throw an exception if
                    serial port is already open by another application
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: Other
        OS/Version: Ubuntu
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: brennen at diyembedded.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Description of Problem:
In Windows, if I have another program with the same serial port open as I am
trying to open in my C# application, then an exception is thrown when I call
SerialPort.Open() on the selected serial port.  A screen capture of the
exception that is thrown in Windows can be found here:
http://www.diyembedded.com/serial_open_exception.jpg

However, in Mono, the serial port still gets opened, regardless of whether or
not another program already has the same serial port open. It even reads and
writes to the serial port at the same time as the other program.

This is very undesirable, as only one program should be running the serial port
at the same time, and there is currently no way (that I am aware of) in Mono to
be sure of this (at least without using Unix system calls, which would break
the Windows build of my code).


Steps to reproduce the problem:
1. Open GtkTerm and connect it to any serial port on the PC (for example,
/dev/ttyS0).
2. Open the same serial port in a C# application using the SerialPort class. 
No exception is thrown when trying to open this serial port.  You could use
code similar to this to test:

void TestFunc()
{
   SerialPort serPort = new SerialPort();
   serPort.PortName = "/dev/ttyS0";

   try
   {
      serPort.Open();
      MessageBox.Show(serPort.PortName + " opened successfully");


      if (serPort2.IsOpen)
      {
         serPort2.Close();
      }
   }
   catch (Exception e)
   {
      MessageBox.Show(e.ToString());
   }
}

Actual Results:
No exception is thrown when opening an already open serial port using the
SerialPort.Open() function.

Expected Results:
An exception should be thrown when opening an already open serial port using
the SerialPort.Open() function.

How often does this happen? 
Every time

Additional Information:
To my knowledge GtkTerm and minicom will both create a file lock on the serial
port they have open.  In Ubuntu, this gets stored in
/var/LCK...<name_of_serial_port>.  Therefore, there needs to be some kind of
locking mechanism added to the code that sits behind SerialPort.Open() in Mono
to attempt to lock the serial port before it gets used.  If the lock fails, an
exception should be thrown.

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list