Unable to reopen Serial COM port without admin privileges RRS feed

  • Question

  • In using a USB serial COM port for data transfer between an UDOO board running Lubuntu 12.04 (Kernel 3.0.35)  and a Toshiba WT310-S1003 tablet PC running Windows 8.1(Professional or Embedded) with .NET 4.5. We have come across a scenario where our application fails to open the COM port even when it can be seen in the device manager. This occurs when the COM port is removed and attached within a very short period of time. The following is the exception that is thrown at our application when it is unable to open the COM port.

    serialPort.Open() error :

    System.IO.IOException: The port 'COM15' does not exist.

       at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)

       at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)

       at System.IO.Ports.SerialPort.Open()


    We have observed that the COM port is not visible to the application when attempting to obtain the serial port via the following call.


    But the serial COM port is visible to the following Devcon command.

                    devcon find =ports

    When the above error occurs, the following are some scenarios which enables the application to open the COM port again. Note that none of these are practical in our scenario, since this is an unattended, consumer facing product / application.

    1.        Terminating the application and re-launching with Administrative privileges. With Admin privileges this issue was ­not recreated. However, it is not an option for us to run our application with Administrative privileges.
    2.        Launching the Windows Device Manager and performing a refresh on the relevant COM port. After this action, the application manages to reconnect to the COM port.
    3.        Launching Windows Device Manager and Disabling and then Enabling the relevant COM Port. After this action the application manages to reconnect to the COM port. We tried invoking devcon through our application but, that failed to refresh the device manager. There were no errors logged, but the usual UI refresh seen in the device manager was not visible.

    Please let us know if there is a solution to regain connectivity to the COM port without Administrative privileges or manual interaction.

    Thursday, October 8, 2015 4:23 AM

All replies

  • If I understand it correctly, your application always connects properly the very first time that it is started. I'm not sure if you keep the port open all the time or that you open, read/write and close again. If so, your application keeps on working till something undefined happens. After which you have to do one of the steps that you described.

    If so, I would try to figure out what this something 'undefined' is. You might have a try/catch somewhere while communicating and the port is not closed when it goes wrong. You might also have a thread that is not stopped when your application 'stops'.

    It's just ideas that come up in my mind.

    Thursday, October 8, 2015 5:32 AM
  • This is what is written in teh documentation:

    "Only one open connection can exist per SerialPort object.

    The best practice for any application is to wait for some amount of time after calling the Close method before attempting to call the Open method, as the port may not be closed instantly."

    Could it be you are jsut trying to re-open it to quickly? Possibly when there is still OS-level cached data being transfered?
    Could it be you are not properly disposing/closing the SerialPort once opened? Have you properly wrapped that use into a using block, or did you do something liek splitting up the opening and disposing of the SerialPort instance? (usually a bad idea).

    Thursday, October 8, 2015 9:43 AM