5 Replies - 12168 Views - Last Post: 10 October 2013 - 10:27 PM Rate Topic: -----

#1 ocaccy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-August 12

How to get the InstanceName from a USB Serial Port?

Posted 29 August 2012 - 09:08 PM

Hi Everyone.
How to get the InstanceName from a USB Serial Port?
if we use the code below will display all Serial Port!
CommPort com=CommPort.Instance;
            int foundRSP=0;

            string[] portList=com.GetAvailablePorts();
            #region This code takes all the serial ports
            for(int i=0;i<portList.Length;++i)
                {
                string name=portList[i];
                comboBox1.Items.Add(name);
                if(name==Settings.Port.PortName)
                    foundRSP=i;
                }

            if(portList.Length>0)
                comboBox1.SelectedIndex=foundRSP;
            #endregion



However I need to show only the USB Serial Port.
I tried this way and not succeeded.
            ManagementObjectSearcher searcher=new ManagementObjectSearcher("root\\WMI","SELECT * FROM MSSerial_PortName");
            string[] USBPorts=System.IO.Ports.SerialPort.GetPortNames();
            #region In this code I need only the USB Serial Port

            //FriendlyName, PID & VID.

            foreach(ManagementObject queryObj in searcher.Get)
                {
                lbl_InstanceName.Text="InstanceName: {0}"+queryObj["InstanceName"];
                lbl_PortName.Text="PortName: {0}"+queryObj["PortName"];

                //If the serial port's instance name contains USB Serial Port
                //it must be a USB to serial device
                if(queryObj["InstanceName"].ToString().Contains("USB Serial Port"))
                    {
                    comboBoxUSB.Items.Add(queryObj["PortName"]);
                    }
                }
            #endregion



All help will be welcome,
ocaccy

Is This A Good Question/Topic? 0
  • +

Replies To: How to get the InstanceName from a USB Serial Port?

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: How to get the InstanceName from a USB Serial Port?

Posted 30 August 2012 - 07:01 AM

All serial ports are listed in the Registry along with the name you see in device manager.

So you could go through those listed and see which entry starts with USB.
Attached Image
Was This Post Helpful? 0
  • +
  • -

#3 ocaccy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-August 12

Re: How to get the InstanceName from a USB Serial Port?

Posted 30 August 2012 - 02:08 PM

Thank you.

This function will need to work on XP, VISTA and 7.
I Would like to work in direction of your tip.
Have you any suggestion to link with code in C# so i can learn?
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: How to get the InstanceName from a USB Serial Port?

Posted 30 August 2012 - 02:11 PM

I already gave you a link for this. See where it says "Registry" in my post and how it is underlined and blue? Click it.
Was This Post Helpful? 0
  • +
  • -

#5 ocaccy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-August 12

Re: How to get the InstanceName from a USB Serial Port?

Posted 30 August 2012 - 02:43 PM

I'm already using that C++ code.
Attached Image
My Desktop is i7,W7Ult & VS2010Ult.
Did not work now. The error message says it is, out of date!
I'm learning with this C++ code for use in C#.
But the problem is not over yet.

For Windows XP and Windows 2000:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\FTDIBUS\VID_VID+PID_PID+Serial_Number\0000\DeviceParameters\PortName
You have a snippet of code in C# to capture the VID, PID and PortName from this line within the registry?
Was This Post Helpful? 0
  • +
  • -

#6 ocaccy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-August 12

Re: How to get the InstanceName from a USB Serial Port?

Posted 10 October 2013 - 10:27 PM

@#4 tlhIn`toq
Thank you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1