Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get a list of USBDeviceInfo[] or a single USBDevice based on VID & PID #13

Open
piotrkundu opened this issue Oct 14, 2015 · 9 comments
Open

Comments

@piotrkundu
Copy link

Add two methods in USBDevice

public static USBDeviceInfo[] GetDevices(int VID, int PID)
public static USBDevice GetSingleDevice(int VID, int PID)

I might have solution for that and I tried to reach out on Codeplex. Pls get back to me.

@madwizard-thomas
Copy link
Owner

The project on codeplex is not the same project, however if you have code to share you can add a pull request here.

@mauriciocirelli
Copy link

Hi,

I am interested on this too. Is there any workaround? I am struggling to find the correct GUID for the device I am trying to connect to.

@Konamiman
Copy link

Konamiman commented Dec 22, 2020

Same here. Being able to get a device from VID and PID bypassing GUIDs would be awesome.

EDIT: I've found this: https://stackoverflow.com/a/13928035/4574

So USBDevice.GetDevices("{A5DCBF10-6530-11D2-901F-00C04FB951ED}") will apparently list all the existing devices (and it seems to indeed work in that way). It would be easy to create a GetAllDevices() method aliasing that. cc @mauriciocirelli

@madwizard-thomas
Copy link
Owner

If that works that may be an easy solution. The device still needs to have a winusb driver though to be able to access it.
What are your use cases btw?

@mauriciocirelli
Copy link

My use case is to automate measurements by sending commands and reading info from a USB to GPIB bridge.
There are some USB to GPIB bridges that work as COM Ports, but the one I have does not work like that and the vendor's API is horribly written. So I was trying to write my own code to work with that device.

@Konamiman
Copy link

Mine is just experimenting. I want to control a USB device from a 8 bit computer that of course doesn't have any drivers for it (it doesn't have the concept of "drivers" to start with), the device is poorly documented so I need to work out the appropriate USB requests in a trial-and-error-ish fashion. Doing that on my PC with your library is going to be a lot easier than directly on the target computer.

@madwizard-thomas
Copy link
Owner

If you are creating the driver (well .inf file) yourself you will have to choose your own GUID anyway so you can use that in your code. If there is an existing driver it has to use WinUSB to be able to use it, and you can also find the GUID in the existing drivers.

@mauriciocirelli
Copy link

If you are creating the driver (well .inf file) yourself you will have to choose your own GUID anyway so you can use that in your code. If there is an existing driver it has to use WinUSB to be able to use it, and you can also find the GUID in the existing drivers.

I know that.. However, the GUID is never documented by driver's developers and it took me several hours to find the correct one on the Windows registries. Other libraries work with VID and PID, but are more complex to use. I think adding this feature would make this library much more developer-friendly.

@kerol2r20
Copy link
Contributor

kerol2r20 commented Mar 3, 2021

Simple implementation

static USBDeviceInfo GetDeviceInfoByVidPid(string guid, UInt16 vid, UInt16 pid)
{
    USBDeviceInfo[] infoList = USBDevice.GetDevices(guid);
    return infoList.FirstOrDefault(info => info.VID == vid && info.PID == pid);
}

static USBDeviceInfo GetDeviceInfoByVidPid(Guid guid, UInt16 vid, UInt16 pid)
{
    USBDeviceInfo[] infoList = USBDevice.GetDevices(guid);
    return infoList.FirstOrDefault(info => info.VID == vid && info.PID == pid);
}

How to set correct GUID?

There are two way I use to create WinUSB boilerplate

The key of GUID is the following part.

[Strings]
; Modify DeviceGUID as you want
DeviceGUID = "{BB9176E8-924F-4a7e-963A-6DC6A4E87FC2}" ;

[AddDeviceInterfaceGUID]
HKR,,DeviceInterfaceGUIDs,0x10000,%DeviceGUID%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants