JulienG
JulienG

Reputation: 11

Write usb bulk windows with winusb

Im trying to send some data using the bulkout endpoint of a usb device. I can open the usb device (corsair k65rgb keyboard) interface 2 (which control the lighting) using createfile and SetupDiGetDeviceInterfaceDetail. But the example code I have write data using HidD_SetFeature. And from the usb sniffer it write urb function classe interface (using the control endpoint) but when I open corsair cue software it use urb function bulk or interrupt transfer.

So I know its possible to send bulk data. But im lost on how to do it Thank you

I use QT 5.9 and VS2015

Upvotes: 0

Views: 1893

Answers (1)

Aravind Prakash
Aravind Prakash

Reputation: 21

You could try the winusb call WinUsb_WritePipe() for transfering data using bulk transfers.

A interface handle is required before we can use WinUsb calls.It is obtained by using setupApi calls and after the required device is found. Use CreateFile() call to open the file handle and perform WinUsb_Initialise() to obtain the interface handle. We can use this interface handle for further WinUsb calls.For Bulk transfer we would also require pipe(Endpoint) information which can be obtained by WinUsb_QueryPipe() call.

Check the following reference for list of winusb calls:
https://learn.microsoft.com/en-us/windows/desktop/api/winusb/
This is an example code for Bulk transfer using a winusb call.

    BOOL WriteToBulkEndpoint(WINUSB_INTERFACE_HANDLE hDeviceHandle, UCHAR* pID, ULONG* pcbWritten)
{
    if (hDeviceHandle==INVALID_HANDLE_VALUE || !pID || !pcbWritten)
    {
        return FALSE;
    }

    BOOL bResult = TRUE;

    UCHAR szBuffer[] = "Hello World";
    ULONG cbSize = strlen(szBuffer);
    ULONG cbSent = 0;

    bResult = WinUsb_WritePipe(hDeviceHandle, *pID, szBuffer, cbSize, &cbSent, 0);
    if(!bResult)
    {
        goto done;
    }

    printf("Wrote to pipe %d: %s \nActual data transferred: %d.\n", *pID, szBuffer, cbSent);
    *pcbWritten = cbSent;


done:
    return bResult;

}

Check the following reference for more details: Refer:

Upvotes: 0

Related Questions