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. Application gets stuck after writing on to COM Port

Application gets stuck after writing on to COM Port

Scheduled Pinned Locked Moved Hardware & Devices
csharphelpcom
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.
  • S Offline
    S Offline
    Sifar 0
    wrote on last edited by
    #1

    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.

    L D 2 Replies Last reply
    0
    • S Sifar 0

      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.

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

      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


      1 Reply Last reply
      0
      • S Sifar 0

        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.

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

        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 the Device Parameters key you'll see PortName (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 .NET SerialPort object. If you successfully open the port, then the device is connected. So you'll want to look for the key HKLM\SYSTEM\CurrentControlSet\Enum\USB\VID_xxxx&PID_xxxx\\Device Parameters and read the PortName 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

        S 1 Reply Last reply
        0
        • D 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 the Device Parameters key you'll see PortName (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 .NET SerialPort object. If you successfully open the port, then the device is connected. So you'll want to look for the key HKLM\SYSTEM\CurrentControlSet\Enum\USB\VID_xxxx&PID_xxxx\\Device Parameters and read the PortName 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

          S Offline
          S Offline
          Sifar 0
          wrote on last edited by
          #4

          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.

          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