• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1023
  • Last Modified:

check if vendor_id / device_id exists,

Hi Experts,

I have two USB modems from different manufacturers, i want my c# script to determine whether it's a Zyxel or a Thomson.

Does anyone have code samples, links or examples that show how c# can retrieve vendor and device id?

Having a look around i'm not even sure it's possible in dotnet without hardware or a USB bus API or somesuch.

Many thanks,

Jon
0
jondanger
Asked:
jondanger
  • 3
  • 2
1 Solution
 
arif_eqbalCommented:
Life would be easy if you had an interface/DLL from the vendors but looks like you want a generic way since you would be communicating with devices from different vendors

Try to see if this helps
http://www.developerfusion.com/article/84338/making-usb-c-friendly/
0
 
arif_eqbalCommented:
A quick look on the net lead to this...
http://www.codeproject.com/KB/cs/USB_HID.aspx

Looks like this is also based on the previous article but it might be easier to use from C# if the code here is a DLL or something...
0
 
jondangerAuthor Commented:
Thanks arif_eqbal, i'd seen both of those links but can't get very far with either.

You're right in that i'd like a generic way.

I think something like parsing the output of Windows' lsusb equivalent will be the answer, but it's not very elegant.


0
 
jondangerAuthor Commented:
Found this:
namespace ConsoleApplication1
{
    using System;
    using System.Collections.Generic;
    using System.Management; // need to add System.Management to your project references.

    class Program
    {
        static void Main( string[] args )
        {
            var usbDevices = GetUSBDevices();

            foreach ( var usbDevice in usbDevices )
            {
                Console.WriteLine( "Device ID: {0}, PNP Device ID: {1}, Description: {2}",
                    usbDevice.DeviceID, usbDevice.PnpDeviceID, usbDevice.Description );
            }
        }

        static List<USBDeviceInfo> GetUSBDevices()
        {
            List<USBDeviceInfo> devices = new List<USBDeviceInfo>();

            var searcher = new ManagementObjectSearcher( @"Select * From Win32_USBHub" );

            foreach ( var device in searcher.Get() )
            {
                devices.Add( new USBDeviceInfo(
                ( string )device.GetPropertyValue( "DeviceID" ),
                ( string )device.GetPropertyValue( "PNPDeviceID" ),
                ( string )device.GetPropertyValue( "Description" )
                ) );
            }

            return devices;
        }
    }

    class USBDeviceInfo
    {
        public USBDeviceInfo( string deviceID, string pnpDeviceID, string description )
        {
            this.DeviceID = deviceID;
            this.PnpDeviceID = pnpDeviceID;
            this.Description = description;
        }
        public string DeviceID { get; private set; }
        public string PnpDeviceID { get; private set; }
        public string Description { get; private set; }
    }
}

Open in new window

0
 
jondangerAuthor Commented:
found some code on stackoverflow that i can modify.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now