Application gets stuck after writing on to COM Port
-
Hi Everyone, I have a windows Application developed with .Net 2005 and C#. It communicates with a device using virtual COM Port. I use Windows XP Home and Prof. It works fine everywhere. But recently I shipped the software to one of my client. There it creates problem. During its first run the software checks all COM Ports by sending specific command and where it finds proper response it detects that the device is attached to that Port. This is a regular process of the software. But, while checking the COM ports the application gets stuck after sending command to COM Port. And only way to close it is from Task Manager. This happens with 4 to 5 system, the client had tried. I have also written Log files, there also after sending Command to com port, nothing is logged. Note : No Anti Virus is installed there; Drivers are installed properly; Device is detected by the system when attached; displayed in device manager Any suggestion or hint will be greatly appreciated...
Regards, -SIFAR.
-
Hi Everyone, I have a windows Application developed with .Net 2005 and C#. It communicates with a device using virtual COM Port. I use Windows XP Home and Prof. It works fine everywhere. But recently I shipped the software to one of my client. There it creates problem. During its first run the software checks all COM Ports by sending specific command and where it finds proper response it detects that the device is attached to that Port. This is a regular process of the software. But, while checking the COM ports the application gets stuck after sending command to COM Port. And only way to close it is from Task Manager. This happens with 4 to 5 system, the client had tried. I have also written Log files, there also after sending Command to com port, nothing is logged. Note : No Anti Virus is installed there; Drivers are installed properly; Device is detected by the system when attached; displayed in device manager Any suggestion or hint will be greatly appreciated...
Regards, -SIFAR.
Sifar - 0 wrote:
the software checks all COM Ports by sending ...
That seems to be a bad idea: COM ports can be busy, allocated, non-existing, or connected to special hardware (modem, infra-red, bluetooth,...). Try the same "sending some command" using HyperTerminal to see it fail. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
Hi Everyone, I have a windows Application developed with .Net 2005 and C#. It communicates with a device using virtual COM Port. I use Windows XP Home and Prof. It works fine everywhere. But recently I shipped the software to one of my client. There it creates problem. During its first run the software checks all COM Ports by sending specific command and where it finds proper response it detects that the device is attached to that Port. This is a regular process of the software. But, while checking the COM ports the application gets stuck after sending command to COM Port. And only way to close it is from Task Manager. This happens with 4 to 5 system, the client had tried. I have also written Log files, there also after sending Command to com port, nothing is logged. Note : No Anti Virus is installed there; Drivers are installed properly; Device is detected by the system when attached; displayed in device manager Any suggestion or hint will be greatly appreciated...
Regards, -SIFAR.
Is this a USB device using a virtual COM port? If so, here's what I do to find the COM port it's connected to. NOTE: I'm not sure what the standard practice is for this, there may be a better way, but this was worked just fine for me so far. If anyone knows of a better, more robust way to do this, I'm open to suggestions. You can determine which COM port the device is connect to by searching the registry under
HKLM\SYSTEM\CurrentControlSet\Enum\USB\VID_xxxx&PID_xxxx
where xxxx is the hex identifier for the VendorID and ProductID of the device. Inside this key is another subkey for each instance of the device, and then in theDevice Parameters
key you'll seePortName
(I think, can't remember off hand exactly what it is). Anyway, the name of the COM port can be found here. You can iterate through each instance in the registry and attempt to open the .NETSerialPort
object. If you successfully open the port, then the device is connected. So you'll want to look for the keyHKLM\SYSTEM\CurrentControlSet\Enum\USB\VID_xxxx&PID_xxxx\\Device Parameters
and read thePortName
value from each instance.foreach(string curPortName in portNames)
{
port.Name = curPortName;
try
{
port.Open();
// Will only break if port.Open() succeeds and does not throw an exception.
break;
}
catch(InvalidOperationException ex)
{
// COM port does not exist, device not connected
}
catch(UnauthorizedAccessException ex){
// COM Port already open
}
}You can check the MSDN documentation for how to read info from the Registry in C#. Dybs
-
Is this a USB device using a virtual COM port? If so, here's what I do to find the COM port it's connected to. NOTE: I'm not sure what the standard practice is for this, there may be a better way, but this was worked just fine for me so far. If anyone knows of a better, more robust way to do this, I'm open to suggestions. You can determine which COM port the device is connect to by searching the registry under
HKLM\SYSTEM\CurrentControlSet\Enum\USB\VID_xxxx&PID_xxxx
where xxxx is the hex identifier for the VendorID and ProductID of the device. Inside this key is another subkey for each instance of the device, and then in theDevice Parameters
key you'll seePortName
(I think, can't remember off hand exactly what it is). Anyway, the name of the COM port can be found here. You can iterate through each instance in the registry and attempt to open the .NETSerialPort
object. If you successfully open the port, then the device is connected. So you'll want to look for the keyHKLM\SYSTEM\CurrentControlSet\Enum\USB\VID_xxxx&PID_xxxx\\Device Parameters
and read thePortName
value from each instance.foreach(string curPortName in portNames)
{
port.Name = curPortName;
try
{
port.Open();
// Will only break if port.Open() succeeds and does not throw an exception.
break;
}
catch(InvalidOperationException ex)
{
// COM port does not exist, device not connected
}
catch(UnauthorizedAccessException ex){
// COM Port already open
}
}You can check the MSDN documentation for how to read info from the Registry in C#. Dybs
Thanx Dybs, I had already tried this approach but it does not work under Windows Vista. Actually, in Vista when you login as Administrator everything works fine. But with users other than Administrator it does not works. Vista creates different registry entries for othe Users. I have found below solution : I have used ManagementObjectCollection and ManagementObjectSearcher.
ManagementObjectCollection ManObjCollection;
ManagementObjectSearcher ManObjSearch;ManObjSearch = new ManagementObjectSearcher("Select * from Win32_PnPEntity");
ManObjCollection = ManObjSearch.Get();
foreach (ManagementObject ManObj in ManObjCollection)
{
if (ManObj["Name"] == "Name You Are Looking For")
{
// Do Some Job..
}
}This has worked fine for me with XP and Vista, (Administrator and Non-Administrator) and it is fast also. Hope this would help you further...
Regards, -SIFAR.