简体   繁体   中英

How to distinguish between usb-serial converters?

I've got 4 usb-serial converters (Prolific) connected to a usb hub. When i look in Device Manager i see the dynamically assigned Com numbers. But after repluging the hub into another usb port or after system reebot those com numbers will sometimes change. Is there a way to update those numbers for every converter without manually searching for those numbers? Basicly I would like to have a method in my C# project that will look for some unique id for every converter and then get new com numbers. Is there a way to do this (tried some wmi queries but without success)?

Today I thought about a workaround. So I got another question. How to obtain info about a usb hub? Basicly I could somehow find my usb hub and then retrieve info about connected into hub ports devices . Then getting com numbers of those devices would be quite easy through wmi query. I used USBView to see that it is possible to obtain such info. I can see a tree beggining from a Root Hub -> Generic USB Hub -> Prolific USB-to-serial Comm Port , but how to do it in code now. Any ideas?

Its Simple, by using win32 native calls you can get,

I just providing a part of code, to help you,

var guidComPorts = Guid.Empty;
        UInt32 dwSize;
        IntPtr hDeviceInfo;
        var buffer = new byte[512];
        var providerName = new[] { };
        var spddDeviceInfo = new SpDevinfoData();
        var bStatus = SetupDiClassGuidsFromName("Ports", ref guidComPorts, 1, out dwSize);
        if (bStatus)
        {
            hDeviceInfo = SetupDiGetClassDevs(
                ref guidComPorts,
                (IntPtr)null,
                (IntPtr)null,
                DigcfPresent | DigcfProfile);
            if (hDeviceInfo.ToInt32() != 0)
            {

                while (true)
                {
                    spddDeviceInfo.CbSize = Marshal.SizeOf(spddDeviceInfo);// IS IT THIS LINE WORK FOR 64 BIT                        
                    bStatus = SetupDiEnumDeviceInfo(hDeviceInfo, nDevice++, ref spddDeviceInfo);
                    break;
                }

            }


            return;
        }

    }

Use this code...

find Friendly names, split string get exact port you look for. I have completed it,it works fine due to some confidentiality reason can't able to provide full code here.

For More Find this link

http://www.codeproject.com/KB/cs/HardwareHelper.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM