Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If I have device will transfer data under interface 2 endpoint 7

but I have no idea how to get device path of interface 2 endpoint 7


my code by step as below:

C++
// declared
SP_DEVINFO_DATA devInfoData;
SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
PSP_INTERFACE_DEVICE_DETAIL_DATA detail = NULL;


//step 1:
HDEVINFO handle = SetupDiGetClassDevs(&USB_DEVICE, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); 

devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);

//step 2
for(memberIndex = 0; SetupDiEnumDeviceInfo(handle, memberIndex, &devInfoData); memberIndex++)
{
     result = SetupDiEnumDeviceInterfaces(handle, NULL, &USB_DEVICE, memberIndex, &deviceInterfaceData);
     if(result)
     {
         //step 3
         // First we get the required buffer size
         result = SetupDiGetDeviceInterfaceDetail(handle, &deviceInterfaceData, NULL, 0, &requiredSize, NULL);

         ...
         detail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) new BYTE[requiredSize];
         detail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);


         //step 4
         result = SetupDiGetDeviceInterfaceDetail(handle, &deviceInterfaceData, detail, requiredSize, NULL, &devInfoData);
         if(!result)
         {
          //Error handle
          continue;
          }


          ...


         //declared
         UINT success;
         char pinBuf[512] = {0}, poutBuf[512] = {0};
         int ReadLen = 512, WriteLen = 512;
         OVERLAPPED ovlp;
         DWORD lpBytesReturnedRead, lpBytesReturnedWrite;

         //this path is my confused point
         //detail->DevicePath is get parent class, but I need get child class path 
         //like under uvc class interface 2 endpoint 7 path

         //my diagram
         <a href="https://db.tt/kdKY28tl">regedit diagram</a>

        // "detail->DevicePath" get the format like this as below:
  // \??\USB#VID_0603&PID_8613#6&293792e1&0&2#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
         HANDLE handleCreateFile = CreateFile(detail->DevicePath,  //<-------point
					GENERIC_WRITE | GENERIC_READ,
					FILE_SHARE_WRITE | FILE_SHARE_READ,
					NULL,
					OPEN_EXISTING,
					FILE_FLAG_OVERLAPPED,
					NULL);
         // how could I get uvc class path under interface 2 endpoint 7
         // this is my confused point ,i have no idea
         // any someone have good idea ,how to get this path or using another method




        //finally
        success = ReadFile(handleCreateFile,
					pinBuf,//&pinBuf,         <----?
					512,
					&lpBytesReturnedRead,   //<----?
					&ovlp                   //<----?
					);
        //the ReadFile where wrong , the success value always return false ??
        // Could any one tell me , how to fill correct Parameters?
        if(!success)
        {
            //do something
        }



     }
Posted

1 solution

You have to find the device path, open it, and then enumerate the interfaces to find and open the interface needed.

The code for this is messy because the API behavior and preferred practices of USB drivers changed from XP, to Vista, 7, and now Windows 8.

Looks like you're doing that with SetupDiEnumDeviceInterfaces and SetupDiGetDeviceInterfaceDetail.

If the device's driver is WinUSB, this is easier because the API is documented. If you are talking to a proprietary driver, you'll have to get the details from them. It may involve ReadFile/WriteFile or IoCtrl calls to do what you want.

Here's the API for finding an endpoint in WinUSB:

http://msdn.microsoft.com/en-us/library/windows/hardware/ff540293%28v=vs.85%29.aspx[^]

There are also a couple of decent WinUSB articles on codeproject.

For a proprietary driver, if you can't get any documentation - there are some utilities to "spy" and the messaging between the driver and application.

http://www.nirsoft.net/utils/device_io_view.html

I am, of course, talking about calls to DeviceIoControl.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363219%28v=vs.85%29.aspx[^]

Some of the USB related IOCTL messages are somewhat standardized.

http://msdn.microsoft.com/en-us/library/windows/hardware/ff537421%28v=vs.85%29.aspx[^]

This is more of a brain dump than a solution but - without more information - is all I can offer.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900