Artem Romanov
Artem Romanov

Reputation: 165

Send packet to usb endpoint

I need to send specified packet (5 byte) to usb zero endpoint. My device installed as com port. I use sample How to Access a USB Device by Using WinUSB Functions

First question: I not find my device if enumerate Ports class devices. My device for some reason is in a Raw data class. How can this be?

Second question: Why is WinUsb_Initialize() return error 87(INVALID PARAMETER).

//GUID InterfaceClassGuid = {0x4D36E978, 0xE325, 0x11CE, 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18}; //Ports class
GUID InterfaceClassGuid = {0xA5DCBF10, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED}; //Raw data

BOOL GetDeviceHandle (GUID guidDeviceInterface, PHANDLE hDeviceHandle){
...
//my code
WCHAR DeviceIDToFind[] = L"vid_xxxx&pid_xxxx";
// lpDevicePath is "\\?\usb#vid_xxxx&pid_xxxx#833435204e3334355f302083a5ada5e0a0e2aee0208faee1e2a0a2aaa0#{a5dcbf10-6530-11d2-901f-00c04fb951ed}"
WCHAR* res = wcsstr(lpDevicePath, DeviceIDToFind);
if (res!=NULL)
    break; //find our device
...
*hDeviceHandle = CreateFile (
    lpDevicePath,
    GENERIC_READ | GENERIC_WRITE,
    FILE_SHARE_READ | FILE_SHARE_WRITE,
    NULL,
    OPEN_EXISTING,
    FILE_FLAG_OVERLAPPED,
    NULL);
    err = GetLastError();// err is 0
...
}
...
WINUSB_INTERFACE_HANDLE h = INVALID_HANDLE_VALUE;
BOOL bResult = WinUsb_Initialize(hDeviceHandle, &h);
err = GetLastError(); // err is 87 INVALID PARAMETER

Upvotes: 1

Views: 2259

Answers (1)

dssepmot
dssepmot

Reputation: 11

You have to set the Vendor ID and Product ID of your device.

your code snippet has the information.

WCHAR DeviceIDToFind[] = L"vid_xxxx&pid_xxxx";

this code has vendor id (vid_xxxx) and product id (pid_xxxx), which xxxx is hex number.

if your device has vid 3259 and pid 1001, you write DeviceIDToFind like below.

WCHAR DeviceIDToFind[] = L"vid_3259&pid_1001";

you have to have much understanding on usb specification. Cheers.

Upvotes: 1

Related Questions