"Port 'COM 3' does not exist"...Except when it does
-
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
-
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
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
-
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
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
-
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
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