libusbK 
3.0
Library Documentation
© 2011-2021 Travis Lee Robinson. All rights reserved.
open-device.c

Locates and opens a device by vid/pid.

open-device example:
  1. Finds a device by vid/pid (use vid=hhhh, pid=hhhhh and the command line).
  2. Initializes a new UsbK (usb device) handle.
  3. Prints pipe information.
  4. Frees the UsbK (usb device) handle.
  5. Frees the LstK (device list) handle created in step #1.
Console Output
Looking for device vid/pid 04D8/FA2E..
Using 04D8:FA2E (LUSBW1): Benchmark Device - Microchip Technology, Inc.
Device opened successfully!
Pipe Information:
  PipeId=0x01 PipeType=0x02 Interval=0 MaximumPacketSize=32
  PipeId=0x81 PipeType=0x02 Interval=0 MaximumPacketSize=32
#include "examples.h"
DWORD __cdecl main(int argc, char* argv[])
{
KLST_HANDLE deviceList = NULL;
KLST_DEVINFO_HANDLE deviceInfo = NULL;
KUSB_HANDLE handle = NULL;
DWORD ec = ERROR_SUCCESS;
UCHAR pipeIndex = 0;
// Find the test device. Uses "vid/pid=hhhh" arguments supplied
// on the command line. (default is: vid=04D8 pid=FA2E)
if (!Examples_GetTestDevice(&deviceList, &deviceInfo, argc, argv))
return GetLastError();
LibK_LoadDriverAPI(&Usb, deviceInfo->DriverID);
// Initialize the device
if (!Usb.Init(&handle, deviceInfo))
{
ec = GetLastError();
printf("Usb.Init failed. ErrorCode: %08Xh\n", ec);
goto Done;
}
printf("Device opened successfully!\n");
// while the device is opened, query information on the endpoints
// of the first alternate setting of the current interface.
printf("Pipe Information:\n");
while (Usb.QueryPipe(handle, 0, pipeIndex++, &pipeInfo))
{
printf(" PipeId=0x%02X PipeType=0x%02X Interval=%u MaximumPacketSize=%u\n",
pipeInfo.PipeId, pipeInfo.PipeType, pipeInfo.Interval, pipeInfo.MaximumPacketSize);
}
Done:
// Close the device handle
// if handle is invalid (NULL), has no effect
Usb.Free(handle);
// Free the device list
// if deviceList is invalid (NULL), has no effect
LstK_Free(deviceList);
return ec;
}
/*
Console Output:
Looking for device vid/pid 04D8/FA2E..
Using 04D8:FA2E (LUSBW1): Benchmark Device - Microchip Technology, Inc.
Device opened successfully!
Pipe Information:
PipeId=0x01 PipeType=0x02 Interval=0 MaximumPacketSize=32
PipeId=0x81 PipeType=0x02 Interval=0 MaximumPacketSize=32
*/