Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Hardware & Devices
  4. "Port 'COM 3' does not exist"...Except when it does

"Port 'COM 3' does not exist"...Except when it does

Scheduled Pinned Locked Moved Hardware & Devices
questioncsharpcomhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dybs
    wrote on last edited by
    #1

    Here's something I just don't get. I have a USB device that enumerates as a virtual COM port (CDC device), so I can use the .NET SerialPort class to communicate with it. For the most part, this works fine. However, sometimes the device just gets disconnected or resets and I need to re-open the COM port (this isn't my actual problem right now, I just need to be able to handle it). I should be able to do this:

    try
    {
    // Serial port communication
    }
    catch(IOException)
    {
    // Device got disconnected, so close our connection.
    port.Close();
    // Wait for device to reconnet.
    Thread.Sleep(5000);
    // We should be able to reconnect to it now (maybe not really, but just assume we can for now).
    port.Open();
    }

    I get a "Port COM 3 does not exist", but if I look in Device Manager, COM 3 clearly exists. I cannot re-open the port until I power off my device AND close my program, then bring them both back up. This happens on XP, Vista, and Win7. NOTE: This is not just a problem with my program - this also happens with HyperTerminal! My colleagues and I suspect it's a problem with the driver, so I've been looking to see if I can find an alternative one. What is the best way to handle this? I have to run some unattended tests that can last 12 or more hours, so if the device resets I can't really automatically close and re-open my program (well, I suppose I could, but I suspect that's more work than I have time to do, and I'd rather not have to keep track of the entire program state and restore it). Thanks, Dybs

    The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen

    L L 2 Replies Last reply
    0
    • D dybs

      Here's something I just don't get. I have a USB device that enumerates as a virtual COM port (CDC device), so I can use the .NET SerialPort class to communicate with it. For the most part, this works fine. However, sometimes the device just gets disconnected or resets and I need to re-open the COM port (this isn't my actual problem right now, I just need to be able to handle it). I should be able to do this:

      try
      {
      // Serial port communication
      }
      catch(IOException)
      {
      // Device got disconnected, so close our connection.
      port.Close();
      // Wait for device to reconnet.
      Thread.Sleep(5000);
      // We should be able to reconnect to it now (maybe not really, but just assume we can for now).
      port.Open();
      }

      I get a "Port COM 3 does not exist", but if I look in Device Manager, COM 3 clearly exists. I cannot re-open the port until I power off my device AND close my program, then bring them both back up. This happens on XP, Vista, and Win7. NOTE: This is not just a problem with my program - this also happens with HyperTerminal! My colleagues and I suspect it's a problem with the driver, so I've been looking to see if I can find an alternative one. What is the best way to handle this? I have to run some unattended tests that can last 12 or more hours, so if the device resets I can't really automatically close and re-open my program (well, I suppose I could, but I suspect that's more work than I have time to do, and I'd rather not have to keep track of the entire program state and restore it). Thanks, Dybs

      The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I recently read a Microsoft web page claiming closing-opening a serial port is likely to fail for unknown reasons, the serial port needs an undetermined delay between close and open, even when nothing went wrong. Unfortunately I didn't save the link. So the only advice I have is: keep the port open and try and make sure nothing ever goes wrong! OTOH I'm not surprised Device Manager, the SerialPort class and/or the serial driver(s) do not always agree on the availability or health status of a port. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      D 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, I recently read a Microsoft web page claiming closing-opening a serial port is likely to fail for unknown reasons, the serial port needs an undetermined delay between close and open, even when nothing went wrong. Unfortunately I didn't save the link. So the only advice I have is: keep the port open and try and make sure nothing ever goes wrong! OTOH I'm not surprised Device Manager, the SerialPort class and/or the serial driver(s) do not always agree on the availability or health status of a port. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        D Offline
        D Offline
        dybs
        wrote on last edited by
        #3

        Luc Pattyn wrote:

        So the only advice I have is: keep the port open and try and make sure nothing ever goes wrong!

        If only it was that simple! Unfortunately, the device can reset for reasons beyond my control (temperature, voltage drop/spike), and even if I keep my port open, I still get an IOException when I try to talk to it once the device is available (I think the error is "port not open"), and I have to reset the connection as I described above. But thanks for the info, I'll see if I can find that link. Dybs

        The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen

        1 Reply Last reply
        0
        • D dybs

          Here's something I just don't get. I have a USB device that enumerates as a virtual COM port (CDC device), so I can use the .NET SerialPort class to communicate with it. For the most part, this works fine. However, sometimes the device just gets disconnected or resets and I need to re-open the COM port (this isn't my actual problem right now, I just need to be able to handle it). I should be able to do this:

          try
          {
          // Serial port communication
          }
          catch(IOException)
          {
          // Device got disconnected, so close our connection.
          port.Close();
          // Wait for device to reconnet.
          Thread.Sleep(5000);
          // We should be able to reconnect to it now (maybe not really, but just assume we can for now).
          port.Open();
          }

          I get a "Port COM 3 does not exist", but if I look in Device Manager, COM 3 clearly exists. I cannot re-open the port until I power off my device AND close my program, then bring them both back up. This happens on XP, Vista, and Win7. NOTE: This is not just a problem with my program - this also happens with HyperTerminal! My colleagues and I suspect it's a problem with the driver, so I've been looking to see if I can find an alternative one. What is the best way to handle this? I have to run some unattended tests that can last 12 or more hours, so if the device resets I can't really automatically close and re-open my program (well, I suppose I could, but I suspect that's more work than I have time to do, and I'd rather not have to keep track of the entire program state and restore it). Thanks, Dybs

          The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Register for plug and play events in the app. When you get a removal notice then close the handle. If you dont then the device willenumerate badly on reset rssulting in either an additional com port or none at all.

          Morality is indistinguishable from social proscription

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups