Solved

check if vendor_id / device_id exists,

Posted on 2010-11-17
5
1,013 Views
Last Modified: 2012-05-10
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
Comment
Question by:jondanger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 34162525
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
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 34162539
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
 

Author Comment

by:jondanger
ID: 34163406
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
 

Accepted Solution

by:
jondanger earned 0 total points
ID: 34163656
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
 

Author Closing Comment

by:jondanger
ID: 34194901
found some code on stackoverflow that i can modify.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question