I fixed the VB error by adding in 2 more WinUsb_GetDescriptor functions.
<DllImport("winusb.dll", SetLastError:=True)> Private Shared Function WinUsb_GetDescriptor _
(ByVal InterfaceHandle As IntPtr, _
ByVal DescriptorType As Byte, _
ByVal Index As Byte, _
ByVal LanguageID As Byte, _
ByVal Buffer As Byte(), _
ByVal BufferLength As UInt32, _
ByRef LengthTransfered As UInt32) _
As Boolean
End Function
<DllImport("winusb.dll", SetLastError:=True)> Private Shared Function WinUsb_GetDescriptor _
(ByVal InterfaceHandle As IntPtr, _
ByVal DescriptorType As Byte, _
ByVal Index As Byte, _
ByVal LanguageID As Byte, _
ByRef deviceDesc As USB_DEVICE_DESCRIPTOR, _
ByVal BufferLength As UInt32, _
ByRef LengthTransfered As UInt32) _
As Boolean
End Function
<DllImport("winusb.dll", SetLastError:=True)> Private Shared Function WinUsb_GetDescriptor _
(ByVal InterfaceHandle As IntPtr, _
ByVal DescriptorType As Byte, _
ByVal Index As Byte, _
ByVal LanguageID As Byte, _
ByRef deviceDesc As USB_CONFIGURATION_DESCRIPTOR, _
ByVal BufferLength As UInt32, _
ByRef LengthTransfered As UInt32) _
As Boolean
End Function
Now, I need to leverage the subroutine below to the VB codes.
private static USBDeviceDescriptor GetDeviceDescriptor(string devicePath)
{
try
{
USBDeviceDescriptor descriptor;
using (API.WinUSBDevice wuDevice = new API.WinUSBDevice())
{
wuDevice.OpenDevice(devicePath);
API.USB_DEVICE_DESCRIPTOR deviceDesc = wuDevice.GetDeviceDescriptor();
// string q = wuDevice.GetStringDescriptor(0);
// TODO: use language id properly
string manufacturer = null, product = null, serialNumber = null;
byte idx = 0;
idx = deviceDesc.iManufacturer;
if (idx > 0)
manufacturer = wuDevice.GetStringDescriptor(idx);
idx = deviceDesc.iProduct;
if (idx > 0)
product = wuDevice.GetStringDescriptor(idx);
idx = deviceDesc.iSerialNumber;
if (idx > 0)
serialNumber = wuDevice.GetStringDescriptor(idx);
descriptor = new USBDeviceDescriptor(devicePath, deviceDesc, manufacturer, product, serialNumber);
}
return descriptor;
}
catch (API.APIException e)
{
throw new USBException("Failed to retrieve device descriptor.", e);
}
}
}