Using WinUSB for Vendor-Defined Functions
371
&GVCKNU
The WINUSB_SETUP_PACKET structure holds the contents of the fields in
the Setup stage’s data packet as described in Chapter 2. The application sets
RequestType to the bmRequestType value for a vendor-specific request directed
to an interface with bit 7 indicating the direction of the Data stage. The
Request, Value, and Index fields are the desired values for bRequest, wValue,
and wIndex in the request.
For a control write request, the application places the data to send to the device
in an array. For a control read request, the application provides an array to hold
data received from the device.
The WinUsb_ControlTransfer function initiates a control transfer. The func-
tion passes a pointer to a WinUSB handle to the interface, a
WINUSB_SETUP_PACKET structure, a byte array that contains data to send
or space for received data, and the number of bytes to read or write. On success,
the function returns True with the number of bytes read or written in the
LengthTransferred parameter.
%NQUKPI%QOOWPKECVKQPU
When finished communicating with a device, the application should free
reserved resources.
8$ Definitions
<DllImport("winusb.dll", SetLastError:=True)> Friend Shared Function WinUsb_Free _
(ByVal InterfaceHandle As IntPtr) _
As Boolean
End Function
Use
WinUsb_Free(myDevInfo.winUsbHandle)
myDevInfo.deviceHandle.Close()
8%
Definitions
[DllImport("winusb.dll", SetLastError = true)]
internal static extern Boolean WinUsb_Free
(IntPtr InterfaceHandle);
Use
WinUsb_Free(myDevInfo.winUsbHandle);
myDevInfo.deviceHandle.Close();