#Region "Copyright (c) Travis Robinson" ' Copyright (c) 2012 Travis Robinson ' All rights reserved. ' ' C# libusbK Bindings ' Auto-generated on: 04.28.2011 ' ' Redistribution and use in source and binary forms, with or without ' modification, are permitted provided that the following conditions are met: ' ' * Redistributions of source code must retain the above copyright ' notice, this list of conditions and the following disclaimer. ' ' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS ' IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ' TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A ' PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TRAVIS LEE ROBINSON ' BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ' CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ' SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ' INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN ' CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ' ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF ' THE POSSIBILITY OF SUCH DAMAGE. #End Region Imports System Imports System.Diagnostics Imports System.Runtime.InteropServices ' ReSharper disable InconsistentNaming ' ReSharper disable CheckNamespace ' ReSharper disable UnassignedReadonlyField Namespace libusbK Public NotInheritable Class AllKOptions Private Sub New() End Sub #Region "Public Members" ''' ''' Alternate libusbK library to use. This must be assigned before any libusbK functions are called and it must be the full path and file name to a libusbK.dll. ''' Public Shared LIBUSBK_FULLPATH_TO_ALTERNATE_DLL As String #End Region End Class Public NotInheritable Class AllKConstants Private Sub New() End Sub #Region "Public Members" ''' ''' Allocated length for all strings in a \ref KLST_DEVINFO structure. ''' Public Const KLST_STRING_MAX_LEN As Integer = 256 ''' ''' libusbK library ''' Public Const LIBUSBK_DLL As String = "libusbK.dll" ''' ''' Config power mask for the \c bmAttributes field of a \ref USB_CONFIGURATION_DESCRIPTOR ''' Public Const USB_CONFIG_POWERED_MASK As Byte = &Hc0 ''' ''' Endpoint address mask for the \c bEndpointAddress field of a \ref USB_ENDPOINT_DESCRIPTOR ''' Public Const USB_ENDPOINT_ADDRESS_MASK As Byte = &Hf ''' ''' Endpoint direction mask for the \c bEndpointAddress field of a \ref USB_ENDPOINT_DESCRIPTOR ''' Public Const USB_ENDPOINT_DIRECTION_MASK As Byte = &H80 #End Region End Class Public Enum PipePolicyType SHORT_PACKET_TERMINATE = &H1 AUTO_CLEAR_STALL = &H2 PIPE_TRANSFER_TIMEOUT = &H3 IGNORE_SHORT_PACKETS = &H4 ALLOW_PARTIAL_READS = &H5 AUTO_FLUSH = &H6 RAW_IO = &H7 MAXIMUM_TRANSFER_SIZE = &H8 RESET_PIPE_ON_RESUME = &H9 ISO_START_LATENCY = &H20 ISO_ALWAYS_START_ASAP = &H21 ISO_NUM_FIXED_PACKETS = &H22 SIMUL_PARALLEL_REQUESTS = &H30 End Enum Public Enum PowerPolicyType AUTO_SUSPEND = &H81 SUSPEND_DELAY = &H83 End Enum Public Enum DeviceInformationType DEVICE_SPEED = &H1 End Enum Public Enum EndpointType ''' ''' Indicates a control endpoint ''' CONTROL = &H0 ''' ''' Indicates an isochronous endpoint ''' ISOCHRONOUS = &H1 ''' ''' Indicates a bulk endpoint ''' BULK = &H2 ''' ''' Indicates an interrupt endpoint ''' INTERRUPT = &H3 ''' ''' Endpoint type mask for the \c bmAttributes field of a \ref USB_ENDPOINT_DESCRIPTOR ''' MASK = &H3 End Enum Public NotInheritable Class ErrorCodes Private Sub New() End Sub #Region "Public Members" ''' ''' Access is denied. ''' Public Const AccessDenied As Integer = 5 ''' ''' The requested resource is in use. ''' Public Const Busy As Integer = 170 ''' ''' The operation was canceled by the user. ''' Public Const Cancelled As Integer = 1223 ''' ''' The library, drive, or media pool is empty. ''' Public Const Empty As Integer = 4306 ''' ''' The handle is invalid. ''' Public Const InvalidHandle As Integer = 6 ''' ''' The parameter is incorrect. ''' Public Const InvalidParameter As Integer = 87 ''' ''' Overlapped I/O event is not in a signaled state. ''' Public Const IoIncomplete As Integer = 996 ''' ''' Overlapped I/O operation is in progress. ''' Public Const IoPending As Integer = 997 ''' ''' More data is available. ''' Public Const MoreData As Integer = 234 ''' ''' No more data is available. ''' Public Const NoMoreItems As Integer = 259 ''' ''' Not enough storage is available to process this command. ''' Public Const NotEnoughMemory As Integer = 8 ''' ''' Element not found. ''' Public Const NotFound As Integer = 1168 ''' ''' The request is not supported. ''' Public Const NotSupported As Integer = 50 ''' ''' The I/O operation has been aborted because of either a thread exit or an application request. ''' Public Const OperationAborted As Integer = 995 ''' ''' The cluster resource is not available. ''' Public Const ResourceNotAvailable As Integer = 5006 ''' ''' The cluster resource could not be found. ''' Public Const ResourceNotFound As Integer = 5007 ''' ''' The semaphore timeout period has expired. ''' Public Const SemTimeout As Integer = 121 ''' ''' The operation completed successfully. ''' Public Const Success As Integer = 0 ''' ''' An attempt was made to operate on a thread within a specific process, but the thread specified is not in the process specified. ''' Public Const ThreadNotInProcess As Integer = 566 ''' ''' A thread termination occurred while the thread was suspended. The thread was resumed, and termination proceeded. ''' Public Const ThreadWasSuspended As Integer = 699 ''' ''' Too many dynamic-link modules are attached to this program or dynamic-link module. ''' Public Const TooManyModules As Integer = 214 #End Region End Class Public Interface IKLIB_HANDLE #Region "Public Members" Function GetContext() As IntPtr ReadOnly Property HandleType() As KLIB_HANDLE_TYPE ReadOnly Property Pointer() As IntPtr Function SetCleanupCallback(CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Function SetContext(UserContext As IntPtr) As Boolean #End Region End Interface #Region "Opaque library handles" Public Structure KLST_HANDLE Implements IKLIB_HANDLE #Region "IKLIB_HANDLE Members" Public ReadOnly Property Pointer() As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType() As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.LSTK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function #End Region #Region "Public Members" Public Sub New(Handle As IntPtr) mHandlePtr = Handle End Sub #End Region #Region "Private Members" Private ReadOnly mHandlePtr As IntPtr #End Region End Structure Public Structure KHOT_HANDLE Implements IKLIB_HANDLE #Region "IKLIB_HANDLE Members" Public ReadOnly Property Pointer() As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType() As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.HOTK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function #End Region #Region "Public Members" Public Sub New(Handle As IntPtr) mHandlePtr = Handle End Sub #End Region #Region "Private Members" Private ReadOnly mHandlePtr As IntPtr #End Region End Structure Public Structure KUSB_HANDLE Implements IKLIB_HANDLE #Region "IKLIB_HANDLE Members" Public ReadOnly Property Pointer() As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType() As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.USBK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function #End Region #Region "USB Shared Device Context" Public Function GetSharedContext() As IntPtr Return AllKFunctions.LibK_GetContext(mHandlePtr, KLIB_HANDLE_TYPE.USBSHAREDK) End Function Public Function SetSharedCleanupCallback(CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, KLIB_HANDLE_TYPE.USBSHAREDK, CleanupCallback) End Function Public Function SetSharedContext(UserContext As IntPtr) As Boolean Return AllKFunctions.LibK_SetContext(mHandlePtr, KLIB_HANDLE_TYPE.USBSHAREDK, UserContext) End Function #End Region #Region "Public Members" Public Sub New(Handle As IntPtr) mHandlePtr = Handle End Sub #End Region #Region "Private Members" Private ReadOnly mHandlePtr As IntPtr #End Region End Structure Public Structure KOVL_POOL_HANDLE Implements IKLIB_HANDLE #Region "IKLIB_HANDLE Members" Public ReadOnly Property Pointer() As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType() As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.OVLPOOLK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function #End Region #Region "Public Members" Public Sub New(Handle As IntPtr) mHandlePtr = Handle End Sub #End Region #Region "Private Members" Private ReadOnly mHandlePtr As IntPtr #End Region End Structure Public Structure KOVL_HANDLE Implements IKLIB_HANDLE #Region "IKLIB_HANDLE Members" Public ReadOnly Property Pointer() As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType() As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.OVLK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function #End Region #Region "Public Members" Public Sub New(Handle As IntPtr) mHandlePtr = Handle End Sub #End Region #Region "Private Members" Private ReadOnly mHandlePtr As IntPtr #End Region End Structure Public Structure KSTM_HANDLE Implements IKLIB_HANDLE #Region "IKLIB_HANDLE Members" Public ReadOnly Property Pointer() As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType() As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.STMK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function #End Region #Region "Public Members" Public Sub New(Handle As IntPtr) mHandlePtr = Handle End Sub #End Region #Region "Private Members" Private ReadOnly mHandlePtr As IntPtr #End Region End Structure #End Region #Region "Internal Function Imports" Friend NotInheritable Class AllKFunctions Private Sub New() End Sub #Region "Delegates" _ Public Delegate Sub HotK_FreeAllDelegate() _ Public Delegate Function HotK_FreeDelegate(<[In]> Handle As KHOT_HANDLE) As Boolean _ Public Delegate Function HotK_InitDelegate( ByRef Handle As KHOT_HANDLE, <[In], Out> ByRef InitParams As KHOT_PARAMS) As Boolean _ Public Delegate Function IsoK_EnumPacketsDelegate(<[In]> IsoContext As KISO_CONTEXT, EnumPackets As KISO_ENUM_PACKETS_CB, StartPacketIndex As Integer, UserState As IntPtr) As Boolean _ Public Delegate Function IsoK_FreeDelegate(<[In]> IsoContext As KISO_CONTEXT) As Boolean _ Public Delegate Function IsoK_GetPacketDelegate(<[In]> IsoContext As KISO_CONTEXT, PacketIndex As Integer, ByRef IsoPacket As KISO_PACKET) As Boolean _ Public Delegate Function IsoK_InitDelegate( ByRef IsoContext As KISO_CONTEXT, NumberOfPackets As Integer, StartFrame As Integer) As Boolean _ Public Delegate Function IsoK_ReUseDelegate(<[In]> IsoContext As KISO_CONTEXT) As Boolean _ Public Delegate Function IsoK_SetPacketDelegate(<[In]> IsoContext As KISO_CONTEXT, PacketIndex As Integer, <[In]> ByRef IsoPacket As KISO_PACKET) As Boolean _ Public Delegate Function IsoK_SetPacketsDelegate(<[In]> IsoContext As KISO_CONTEXT, PacketSize As Integer) As Boolean _ Public Delegate Sub LibK_Context_FreeDelegate() _ Public Delegate Function LibK_Context_InitDelegate(Heap As IntPtr, Reserved As IntPtr) As Boolean _ Public Delegate Function LibK_CopyDriverAPIDelegate( ByRef DriverAPI As KUSB_DRIVER_API, <[In]> UsbHandle As KUSB_HANDLE) As Boolean _ Public Delegate Function LibK_GetContextDelegate(<[In]> Handle As IntPtr, HandleType As KLIB_HANDLE_TYPE) As IntPtr _ Public Delegate Function LibK_GetDefaultContextDelegate(HandleType As KLIB_HANDLE_TYPE) As IntPtr _ Public Delegate Function LibK_GetProcAddressDelegate(ProcAddress As IntPtr, DriverID As Integer, FunctionID As Integer) As Boolean _ Public Delegate Sub LibK_GetVersionDelegate( ByRef Version As KLIB_VERSION) _ Public Delegate Function LibK_LoadDriverAPIDelegate( ByRef DriverAPI As KUSB_DRIVER_API, DriverID As Integer) As Boolean _ Public Delegate Function LibK_SetCleanupCallbackDelegate(<[In]> Handle As IntPtr, HandleType As KLIB_HANDLE_TYPE, CleanupCB As KLIB_HANDLE_CLEANUP_CB) As Boolean _ Public Delegate Function LibK_SetContextDelegate(<[In]> Handle As IntPtr, HandleType As KLIB_HANDLE_TYPE, ContextValue As IntPtr) As Boolean _ Public Delegate Function LibK_SetDefaultContextDelegate(HandleType As KLIB_HANDLE_TYPE, ContextValue As IntPtr) As Boolean _ Public Delegate Function LstK_CountDelegate(<[In]> DeviceList As KLST_HANDLE, ByRef Count As Integer) As Boolean _ Public Delegate Function LstK_CurrentDelegate(<[In]> DeviceList As KLST_HANDLE, ByRef DeviceInfo As KLST_DEVINFO_HANDLE) As Boolean _ Public Delegate Function LstK_EnumerateDelegate(<[In]> DeviceList As KLST_HANDLE, EnumDevListCB As KLST_ENUM_DEVINFO_CB, Context As IntPtr) As Boolean _ Public Delegate Function LstK_FindByVidPidDelegate(<[In]> DeviceList As KLST_HANDLE, Vid As Integer, Pid As Integer, ByRef DeviceInfo As KLST_DEVINFO_HANDLE) As Boolean _ Public Delegate Function LstK_FreeDelegate(<[In]> DeviceList As KLST_HANDLE) As Boolean _ Public Delegate Function LstK_InitDelegate( ByRef DeviceList As KLST_HANDLE, Flags As KLST_FLAG) As Boolean _ Public Delegate Function LstK_InitExDelegate( ByRef DeviceList As KLST_HANDLE, Flags As KLST_FLAG, <[In]> ByRef PatternMatch As KLST_PATTERN_MATCH) As Boolean _ Public Delegate Function LstK_MoveNextDelegate(<[In]> DeviceList As KLST_HANDLE, ByRef DeviceInfo As KLST_DEVINFO_HANDLE) As Boolean _ Public Delegate Sub LstK_MoveResetDelegate(<[In]> DeviceList As KLST_HANDLE) _ Public Delegate Function OvlK_AcquireDelegate( ByRef OverlappedK As KOVL_HANDLE, <[In]> PoolHandle As KOVL_POOL_HANDLE) As Boolean _ Public Delegate Function OvlK_FreeDelegate(<[In]> PoolHandle As KOVL_POOL_HANDLE) As Boolean _ Public Delegate Function OvlK_GetEventHandleDelegate(<[In]> OverlappedK As KOVL_HANDLE) As IntPtr _ Public Delegate Function OvlK_InitDelegate( ByRef PoolHandle As KOVL_POOL_HANDLE, <[In]> UsbHandle As KUSB_HANDLE, MaxOverlappedCount As Integer, Flags As KOVL_POOL_FLAG) As Boolean _ Public Delegate Function OvlK_IsCompleteDelegate(<[In]> OverlappedK As KOVL_HANDLE) As Boolean _ Public Delegate Function OvlK_ReUseDelegate(<[In]> OverlappedK As KOVL_HANDLE) As Boolean _ Public Delegate Function OvlK_ReleaseDelegate(<[In]> OverlappedK As KOVL_HANDLE) As Boolean _ Public Delegate Function OvlK_WaitAndReleaseDelegate(<[In]> OverlappedK As KOVL_HANDLE, TimeoutMS As Integer, ByRef TransferredLength As Integer) As Boolean _ Public Delegate Function OvlK_WaitDelegate(<[In]> OverlappedK As KOVL_HANDLE, TimeoutMS As Integer, WaitFlags As KOVL_WAIT_FLAG, ByRef TransferredLength As Integer) As Boolean _ Public Delegate Function OvlK_WaitOldestDelegate(<[In]> PoolHandle As KOVL_POOL_HANDLE, ByRef OverlappedK As KOVL_HANDLE, TimeoutMS As Integer, WaitFlags As KOVL_WAIT_FLAG, ByRef TransferredLength As Integer) As Boolean _ Public Delegate Function OvlK_WaitOrCancelDelegate(<[In]> OverlappedK As KOVL_HANDLE, TimeoutMS As Integer, ByRef TransferredLength As Integer) As Boolean _ Public Delegate Function StmK_FreeDelegate(<[In]> StreamHandle As KSTM_HANDLE) As Boolean _ Public Delegate Function StmK_InitDelegate( ByRef StreamHandle As KSTM_HANDLE, <[In]> UsbHandle As KUSB_HANDLE, PipeID As Byte, MaxTransferSize As Integer, MaxPendingTransfers As Integer, MaxPendingIO As Integer, _ <[In]> ByRef Callbacks As KSTM_CALLBACK, Flags As KSTM_FLAG) As Boolean _ Public Delegate Function StmK_ReadDelegate(<[In]> StreamHandle As KSTM_HANDLE, Buffer As IntPtr, Offset As Integer, Length As Integer, ByRef TransferredLength As Integer) As Boolean _ Public Delegate Function StmK_StartDelegate(<[In]> StreamHandle As KSTM_HANDLE) As Boolean _ Public Delegate Function StmK_StopDelegate(<[In]> StreamHandle As KSTM_HANDLE, TimeoutCancelMS As Integer) As Boolean _ Public Delegate Function StmK_WriteDelegate(<[In]> StreamHandle As KSTM_HANDLE, Buffer As IntPtr, Offset As Integer, Length As Integer, ByRef TransferredLength As Integer) As Boolean _ Public Delegate Function UsbK_FreeDelegate(<[In]> InterfaceHandle As KUSB_HANDLE) As Boolean #End Region Shared Sub New() If [String].IsNullOrEmpty(AllKOptions.LIBUSBK_FULLPATH_TO_ALTERNATE_DLL) Then mModuleLibusbK = LoadLibraryEx(AllKConstants.LIBUSBK_DLL, IntPtr.Zero, LoadLibraryFlags.NONE) Else mModuleLibusbK = LoadLibraryEx(AllKOptions.LIBUSBK_FULLPATH_TO_ALTERNATE_DLL, IntPtr.Zero, LoadLibraryFlags.LOAD_WITH_ALTERED_SEARCH_PATH) End If If mModuleLibusbK = IntPtr.Zero Then Throw New DllNotFoundException("libusbK.dll not found. Please install drivers/applications and retry.") End If LoadDynamicFunctions() End Sub #Region "Nested Enumerations" _ Private Enum LoadLibraryFlags NONE = 0 DONT_RESOLVE_DLL_REFERENCES = &H1 LOAD_IGNORE_CODE_AUTHZ_LEVEL = &H10 LOAD_LIBRARY_AS_DATAFILE = &H2 LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = &H40 LOAD_LIBRARY_AS_IMAGE_RESOURCE = &H20 LOAD_WITH_ALTERED_SEARCH_PATH = &H8 End Enum #End Region #Region "Public Members" Public Shared HotK_Free As HotK_FreeDelegate Public Shared HotK_FreeAll As HotK_FreeAllDelegate Public Shared HotK_Init As HotK_InitDelegate Public Shared IsoK_EnumPackets As IsoK_EnumPacketsDelegate Public Shared IsoK_Free As IsoK_FreeDelegate Public Shared IsoK_GetPacket As IsoK_GetPacketDelegate Public Shared IsoK_Init As IsoK_InitDelegate Public Shared IsoK_ReUse As IsoK_ReUseDelegate Public Shared IsoK_SetPacket As IsoK_SetPacketDelegate Public Shared IsoK_SetPackets As IsoK_SetPacketsDelegate Public Shared LibK_Context_Free As LibK_Context_FreeDelegate Public Shared LibK_Context_Init As LibK_Context_InitDelegate Public Shared LibK_CopyDriverAPI As LibK_CopyDriverAPIDelegate Public Shared LibK_GetContext As LibK_GetContextDelegate Public Shared LibK_GetDefaultContext As LibK_GetDefaultContextDelegate Public Shared LibK_GetProcAddress As LibK_GetProcAddressDelegate Public Shared LibK_GetVersion As LibK_GetVersionDelegate Public Shared LibK_LoadDriverAPI As LibK_LoadDriverAPIDelegate Public Shared LibK_SetCleanupCallback As LibK_SetCleanupCallbackDelegate Public Shared LibK_SetContext As LibK_SetContextDelegate Public Shared LibK_SetDefaultContext As LibK_SetDefaultContextDelegate Public Shared LstK_Count As LstK_CountDelegate Public Shared LstK_Current As LstK_CurrentDelegate Public Shared LstK_Enumerate As LstK_EnumerateDelegate Public Shared LstK_FindByVidPid As LstK_FindByVidPidDelegate Public Shared LstK_Free As LstK_FreeDelegate Public Shared LstK_Init As LstK_InitDelegate Public Shared LstK_InitEx As LstK_InitExDelegate Public Shared LstK_MoveNext As LstK_MoveNextDelegate Public Shared LstK_MoveReset As LstK_MoveResetDelegate Public Shared OvlK_Acquire As OvlK_AcquireDelegate Public Shared OvlK_Free As OvlK_FreeDelegate Public Shared OvlK_GetEventHandle As OvlK_GetEventHandleDelegate Public Shared OvlK_Init As OvlK_InitDelegate Public Shared OvlK_IsComplete As OvlK_IsCompleteDelegate Public Shared OvlK_ReUse As OvlK_ReUseDelegate Public Shared OvlK_Release As OvlK_ReleaseDelegate Public Shared OvlK_Wait As OvlK_WaitDelegate Public Shared OvlK_WaitAndRelease As OvlK_WaitAndReleaseDelegate Public Shared OvlK_WaitOldest As OvlK_WaitOldestDelegate Public Shared OvlK_WaitOrCancel As OvlK_WaitOrCancelDelegate Public Shared StmK_Free As StmK_FreeDelegate Public Shared StmK_Init As StmK_InitDelegate Public Shared StmK_Read As StmK_ReadDelegate Public Shared StmK_Start As StmK_StartDelegate Public Shared StmK_Stop As StmK_StopDelegate Public Shared StmK_Write As StmK_WriteDelegate Public Shared UsbK_Free As UsbK_FreeDelegate #End Region #Region "Private Members" Private Declare Ansi Function GetProcAddress Lib "kernel32.dll" (hModule As IntPtr, procName As String) As IntPtr Private Shared Sub LoadDynamicFunctions() LibK_GetVersion = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_GetVersion"), GetType(LibK_GetVersionDelegate)), LibK_GetVersionDelegate) LibK_GetContext = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_GetContext"), GetType(LibK_GetContextDelegate)), LibK_GetContextDelegate) LibK_SetContext = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_SetContext"), GetType(LibK_SetContextDelegate)), LibK_SetContextDelegate) LibK_SetCleanupCallback = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_SetCleanupCallback"), GetType(LibK_SetCleanupCallbackDelegate)), LibK_SetCleanupCallbackDelegate) LibK_LoadDriverAPI = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_LoadDriverAPI"), GetType(LibK_LoadDriverAPIDelegate)), LibK_LoadDriverAPIDelegate) LibK_CopyDriverAPI = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_CopyDriverAPI"), GetType(LibK_CopyDriverAPIDelegate)), LibK_CopyDriverAPIDelegate) LibK_GetProcAddress = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_GetProcAddress"), GetType(LibK_GetProcAddressDelegate)), LibK_GetProcAddressDelegate) LibK_SetDefaultContext = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_SetDefaultContext"), GetType(LibK_SetDefaultContextDelegate)), LibK_SetDefaultContextDelegate) LibK_GetDefaultContext = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_GetDefaultContext"), GetType(LibK_GetDefaultContextDelegate)), LibK_GetDefaultContextDelegate) LibK_Context_Init = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_Context_Init"), GetType(LibK_Context_InitDelegate)), LibK_Context_InitDelegate) LibK_Context_Free = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_Context_Free"), GetType(LibK_Context_FreeDelegate)), LibK_Context_FreeDelegate) UsbK_Free = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "UsbK_Free"), GetType(UsbK_FreeDelegate)), UsbK_FreeDelegate) LstK_Init = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_Init"), GetType(LstK_InitDelegate)), LstK_InitDelegate) LstK_InitEx = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_InitEx"), GetType(LstK_InitExDelegate)), LstK_InitExDelegate) LstK_Free = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_Free"), GetType(LstK_FreeDelegate)), LstK_FreeDelegate) LstK_Enumerate = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_Enumerate"), GetType(LstK_EnumerateDelegate)), LstK_EnumerateDelegate) LstK_Current = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_Current"), GetType(LstK_CurrentDelegate)), LstK_CurrentDelegate) LstK_MoveNext = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_MoveNext"), GetType(LstK_MoveNextDelegate)), LstK_MoveNextDelegate) LstK_MoveReset = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_MoveReset"), GetType(LstK_MoveResetDelegate)), LstK_MoveResetDelegate) LstK_FindByVidPid = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_FindByVidPid"), GetType(LstK_FindByVidPidDelegate)), LstK_FindByVidPidDelegate) LstK_Count = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_Count"), GetType(LstK_CountDelegate)), LstK_CountDelegate) HotK_Init = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "HotK_Init"), GetType(HotK_InitDelegate)), HotK_InitDelegate) HotK_Free = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "HotK_Free"), GetType(HotK_FreeDelegate)), HotK_FreeDelegate) HotK_FreeAll = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "HotK_FreeAll"), GetType(HotK_FreeAllDelegate)), HotK_FreeAllDelegate) OvlK_Acquire = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_Acquire"), GetType(OvlK_AcquireDelegate)), OvlK_AcquireDelegate) OvlK_Release = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_Release"), GetType(OvlK_ReleaseDelegate)), OvlK_ReleaseDelegate) OvlK_Init = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_Init"), GetType(OvlK_InitDelegate)), OvlK_InitDelegate) OvlK_Free = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_Free"), GetType(OvlK_FreeDelegate)), OvlK_FreeDelegate) OvlK_GetEventHandle = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_GetEventHandle"), GetType(OvlK_GetEventHandleDelegate)), OvlK_GetEventHandleDelegate) OvlK_Wait = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_Wait"), GetType(OvlK_WaitDelegate)), OvlK_WaitDelegate) OvlK_WaitOldest = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_WaitOldest"), GetType(OvlK_WaitOldestDelegate)), OvlK_WaitOldestDelegate) OvlK_WaitOrCancel = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_WaitOrCancel"), GetType(OvlK_WaitOrCancelDelegate)), OvlK_WaitOrCancelDelegate) OvlK_WaitAndRelease = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_WaitAndRelease"), GetType(OvlK_WaitAndReleaseDelegate)), OvlK_WaitAndReleaseDelegate) OvlK_IsComplete = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_IsComplete"), GetType(OvlK_IsCompleteDelegate)), OvlK_IsCompleteDelegate) OvlK_ReUse = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_ReUse"), GetType(OvlK_ReUseDelegate)), OvlK_ReUseDelegate) StmK_Init = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "StmK_Init"), GetType(StmK_InitDelegate)), StmK_InitDelegate) StmK_Free = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "StmK_Free"), GetType(StmK_FreeDelegate)), StmK_FreeDelegate) StmK_Start = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "StmK_Start"), GetType(StmK_StartDelegate)), StmK_StartDelegate) StmK_Stop = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "StmK_Stop"), GetType(StmK_StopDelegate)), StmK_StopDelegate) StmK_Read = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "StmK_Read"), GetType(StmK_ReadDelegate)), StmK_ReadDelegate) StmK_Write = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "StmK_Write"), GetType(StmK_WriteDelegate)), StmK_WriteDelegate) IsoK_Init = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_Init"), GetType(IsoK_InitDelegate)), IsoK_InitDelegate) IsoK_Free = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_Free"), GetType(IsoK_FreeDelegate)), IsoK_FreeDelegate) IsoK_SetPackets = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_SetPackets"), GetType(IsoK_SetPacketsDelegate)), IsoK_SetPacketsDelegate) IsoK_SetPacket = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_SetPacket"), GetType(IsoK_SetPacketDelegate)), IsoK_SetPacketDelegate) IsoK_GetPacket = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_GetPacket"), GetType(IsoK_GetPacketDelegate)), IsoK_GetPacketDelegate) IsoK_EnumPackets = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_EnumPackets"), GetType(IsoK_EnumPacketsDelegate)), IsoK_EnumPacketsDelegate) IsoK_ReUse = DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_ReUse"), GetType(IsoK_ReUseDelegate)), IsoK_ReUseDelegate) End Sub _ Private Shared Function LoadLibraryEx(lpFileName As String, hReservedNull As IntPtr, dwFlags As LoadLibraryFlags) As IntPtr End Function Private Shared ReadOnly mModuleLibusbK As IntPtr = IntPtr.Zero #End Region End Class #End Region #Region "Enumerations" ''' Values used in the \c bmAttributes field of a \ref USB_ENDPOINT_DESCRIPTOR Public Enum USBD_PIPE_TYPE ''' Indicates a control endpoint UsbdPipeTypeControl ''' Indicates an isochronous endpoint UsbdPipeTypeIsochronous ''' Indicates a bulk endpoint UsbdPipeTypeBulk ''' Indicates an interrupt endpoint UsbdPipeTypeInterrupt End Enum ''' Additional ISO transfer flags. _ Public Enum KISO_FLAG NONE = 0 ''' Do not start the transfer immediately, instead use \ref KISO_CONTEXT::StartFrame. SET_START_FRAME = &H1 End Enum ''' Handle type enumeration. Public Enum KLIB_HANDLE_TYPE ''' Hot plug handle. \ref KHOT_HANDLE HOTK ''' USB handle. \ref KUSB_HANDLE USBK ''' Shared USB handle. \ref KUSB_HANDLE USBSHAREDK ''' Device list handle. \ref KLST_HANDLE LSTK ''' Device info handle. \ref KLST_DEVINFO_HANDLE LSTINFOK ''' Overlapped handle. \ref KOVL_HANDLE OVLK ''' Overlapped pool handle. \ref KOVL_POOL_HANDLE OVLPOOLK ''' Pipe stream handle. \ref KSTM_HANDLE STMK ''' Max handle type count. COUNT End Enum ''' Device list sync flags. _ Public Enum KLST_SYNC_FLAG ''' Cleared/invalid state. NONE = 0 ''' Unchanged state, UNCHANGED = &H1 ''' Added (Arrival) state, ADDED = &H2 ''' Removed (Unplugged) state, REMOVED = &H4 ''' Connect changed state. CONNECT_CHANGE = &H8 ''' All states. MASK = &Hf End Enum ''' Device list initialization flags. _ Public Enum KLST_FLAG ''' No flags (or 0) NONE = 0 ''' Enable listings for the raw device interface GUID \b only. {A5DCBF10-6530-11D2-901F-00C04FB951ED} INCLUDE_RAWGUID = &H1 ''' List all libusbK devices including those not currently connected. INCLUDE_DISCONNECT = &H2 End Enum ''' bmRequest.Dir Public Enum BMREQUEST_DIR HOST_TO_DEVICE = 0 DEVICE_TO_HOST = 1 End Enum ''' bmRequest.Type Public Enum BMREQUEST_TYPE ''' Standard request. See \ref USB_REQUEST_ENUM STANDARD = 0 ''' Class-specific request. [CLASS] = 1 ''' Vendor-specific request VENDOR = 2 End Enum ''' bmRequest.Recipient Public Enum BMREQUEST_RECIPIENT ''' Request is for a device. DEVICE = 0 ''' Request is for an interface of a device. [INTERFACE] = 1 ''' Request is for an endpoint of a device. ENDPOINT = 2 ''' Request is for a vendor-specific purpose. OTHER = 3 End Enum ''' Values for the bits returned by the \ref USB_REQUEST_GET_STATUS request. Public Enum USB_GETSTATUS ''' Device is self powered SELF_POWERED = &H1 ''' Device can wake the system from a low power/sleeping state. REMOTE_WAKEUP_ENABLED = &H2 End Enum ''' Standard USB descriptor types. For more information, see section 9-5 of the USB 3.0 specifications. Public Enum USB_DESCRIPTOR_TYPE ''' Device descriptor type. DEVICE = &H1 ''' Configuration descriptor type. CONFIGURATION = &H2 ''' String descriptor type. [STRING] = &H3 ''' Interface descriptor type. [INTERFACE] = &H4 ''' Endpoint descriptor type. ENDPOINT = &H5 ''' Device qualifier descriptor type. DEVICE_QUALIFIER = &H6 ''' Config power descriptor type. CONFIG_POWER = &H7 ''' Interface power descriptor type. INTERFACE_POWER = &H8 ''' Interface association descriptor type. INTERFACE_ASSOCIATION = &Hb End Enum ''' Usb handle specific properties that can be retrieved with \ref UsbK_GetProperty. Public Enum KUSB_PROPERTY ''' Get the internal device file handle used for operations such as GetOverlappedResult or DeviceIoControl. DEVICE_FILE_HANDLE COUNT End Enum ''' Supported driver id enumeration. Public Enum KUSB_DRVID ''' libusbK.sys driver ID LIBUSBK ''' libusb0.sys driver ID LIBUSB0 ''' WinUSB.sys driver ID WINUSB ''' libusb0.sys filter driver ID LIBUSB0_FILTER ''' Supported driver count COUNT End Enum ''' Supported function id enumeration. Public Enum KUSB_FNID ''' \ref UsbK_Init dynamic driver function id. Init ''' \ref UsbK_Free dynamic driver function id. Free ''' \ref UsbK_ClaimInterface dynamic driver function id. ClaimInterface ''' \ref UsbK_ReleaseInterface dynamic driver function id. ReleaseInterface ''' \ref UsbK_SetAltInterface dynamic driver function id. SetAltInterface ''' \ref UsbK_GetAltInterface dynamic driver function id. GetAltInterface ''' \ref UsbK_GetDescriptor dynamic driver function id. GetDescriptor ''' \ref UsbK_ControlTransfer dynamic driver function id. ControlTransfer ''' \ref UsbK_SetPowerPolicy dynamic driver function id. SetPowerPolicy ''' \ref UsbK_GetPowerPolicy dynamic driver function id. GetPowerPolicy ''' \ref UsbK_SetConfiguration dynamic driver function id. SetConfiguration ''' \ref UsbK_GetConfiguration dynamic driver function id. GetConfiguration ''' \ref UsbK_ResetDevice dynamic driver function id. ResetDevice ''' \ref UsbK_Initialize dynamic driver function id. Initialize ''' \ref UsbK_SelectInterface dynamic driver function id. SelectInterface ''' \ref UsbK_GetAssociatedInterface dynamic driver function id. GetAssociatedInterface ''' \ref UsbK_Clone dynamic driver function id. Clone ''' \ref UsbK_QueryInterfaceSettings dynamic driver function id. QueryInterfaceSettings ''' \ref UsbK_QueryDeviceInformation dynamic driver function id. QueryDeviceInformation ''' \ref UsbK_SetCurrentAlternateSetting dynamic driver function id. SetCurrentAlternateSetting ''' \ref UsbK_GetCurrentAlternateSetting dynamic driver function id. GetCurrentAlternateSetting ''' \ref UsbK_QueryPipe dynamic driver function id. QueryPipe ''' \ref UsbK_SetPipePolicy dynamic driver function id. SetPipePolicy ''' \ref UsbK_GetPipePolicy dynamic driver function id. GetPipePolicy ''' \ref UsbK_ReadPipe dynamic driver function id. ReadPipe ''' \ref UsbK_WritePipe dynamic driver function id. WritePipe ''' \ref UsbK_ResetPipe dynamic driver function id. ResetPipe ''' \ref UsbK_AbortPipe dynamic driver function id. AbortPipe ''' \ref UsbK_FlushPipe dynamic driver function id. FlushPipe ''' \ref UsbK_IsoReadPipe dynamic driver function id. IsoReadPipe ''' \ref UsbK_IsoWritePipe dynamic driver function id. IsoWritePipe ''' \ref UsbK_GetCurrentFrameNumber dynamic driver function id. GetCurrentFrameNumber ''' \ref UsbK_GetOverlappedResult dynamic driver function id. GetOverlappedResult ''' \ref UsbK_GetProperty dynamic driver function id. GetProperty ''' Supported function count COUNT End Enum ''' Hot plug config flags. _ Public Enum KHOT_FLAG ''' No flags (or 0) NONE ''' Notify all devices which match upon a succuessful call to \ref HotK_Init. PLUG_ALL_ON_INIT = &H1 ''' Allow other \ref KHOT_HANDLE instances to consume this match. PASS_DUPE_INSTANCE = &H2 ''' If a \c UserHwnd is specified, use \c PostMessage instead of \c SendMessage. POST_USER_MESSAGE = &H4 End Enum ''' \c WaitFlags used by \ref OvlK_Wait. _ Public Enum KOVL_WAIT_FLAG ''' Do not perform any additional actions upon exiting \ref OvlK_Wait. NONE = 0 ''' If the i/o operation completes successfully, release the OverlappedK back to it's pool. RELEASE_ON_SUCCESS = &H1 ''' If the i/o operation fails, release the OverlappedK back to it's pool. RELEASE_ON_FAIL = &H2 ''' If the i/o operation fails or completes successfully, release the OverlappedK back to its pool. Perform no actions if it times-out. RELEASE_ON_SUCCESS_FAIL = &H3 ''' If the i/o operation times-out cancel it, but do not release the OverlappedK back to its pool. CANCEL_ON_TIMEOUT = &H4 ''' If the i/o operation times-out, cancel it and release the OverlappedK back to its pool. RELEASE_ON_TIMEOUT = &Hc ''' Always release the OverlappedK back to its pool. If the operation timed-out, cancel it before releasing back to its pool. RELEASE_ALWAYS = &Hf ''' Uses alterable wait functions. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms687036%28v=vs.85%29.aspx ALERTABLE = &H10 End Enum ''' \c Overlapped pool config flags. _ Public Enum KOVL_POOL_FLAG NONE = 0 End Enum ''' Stream config flags. _ Public Enum KSTM_FLAG As UInteger ''' None NONE = 0 NO_PARTIAL_XFERS = &H100000 USE_TIMEOUT = &H80000000UI TIMEOUT_MASK = &H1ffff End Enum ''' Stream config flags. Public Enum KSTM_COMPLETE_RESULT ''' Valid VALID = 0 ''' Invalid INVALID End Enum #End Region #Region "Structs" ''' The \c WINUSB_PIPE_INFORMATION structure contains pipe information that the \ref UsbK_QueryPipe routine retrieves. _ Public Structure WINUSB_PIPE_INFORMATION ''' A \c USBD_PIPE_TYPE enumeration value that specifies the pipe type Public PipeType As USBD_PIPE_TYPE ''' The pipe identifier (ID) Public PipeId As Byte ''' The maximum size, in bytes, of the packets that are transmitted on the pipe Public MaximumPacketSize As UShort ''' The pipe interval Public Interval As Byte Public Overrides Function ToString() As String Return String.Format("PipeType: {0}" & vbLf & "PipeId: {1}" & vbLf & "MaximumPacketSize: {2}" & vbLf & "Interval: {3}" & vbLf, PipeType, PipeId.ToString("X2") & "h", MaximumPacketSize, Interval.ToString("X2") & "h") End Function End Structure ''' The \c WINUSB_SETUP_PACKET structure describes a USB setup packet. _ Public Structure WINUSB_SETUP_PACKET ''' The request type. The values that are assigned to this member are defined in Table 9.2 of section 9.3 of the Universal Serial Bus (USB) specification (www.usb.org). Public RequestType As Byte ''' The device request. The values that are assigned to this member are defined in Table 9.3 of section 9.4 of the Universal Serial Bus (USB) specification. Public Request As Byte ''' The meaning of this member varies according to the request. For an explanation of this member, see the Universal Serial Bus (USB) specification. Public Value As UShort ''' The meaning of this member varies according to the request. For an explanation of this member, see the Universal Serial Bus (USB) specification. Public Index As UShort ''' The number of bytes to transfer. (not including the \c WINUSB_SETUP_PACKET itself) Public Length As UShort Public Overrides Function ToString() As String Return String.Format("RequestType: {0}" & vbLf & "Request: {1}" & vbLf & "Value: {2}" & vbLf & "Index: {3}" & vbLf & "Length: {4}" & vbLf, RequestType.ToString("X2") & "h", Request.ToString("X2") & "h", Value.ToString("X4") & "h", Index.ToString("X4") & "h", Length) End Function End Structure ''' Structure describing an isochronous transfer packet. _ Public Structure KISO_PACKET ''' Specifies the offset, in bytes, of the buffer for this packet from the beginning of the entire isochronous transfer data buffer. Public Offset As Integer ''' Set by the host controller to indicate the actual number of bytes received by the device for isochronous IN transfers. Length not used for isochronous OUT transfers. Public Length As UShort ''' Contains the 16 least significant USBD status bits, on return from the host controller driver, of this transfer packet. Public Status As UShort Public Overrides Function ToString() As String Return String.Format("Offset: {0}" & vbLf & "Length: {1}" & vbLf & "Status: {2}" & vbLf, Offset, Length, Status.ToString("X4") & "h") End Function End Structure _ Public Structure KISO_CONTEXT Private ReadOnly mHandlePtr As IntPtr Public Sub New(Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer() As IntPtr Get Return mHandlePtr End Get End Property ''' KISO_CONTEXT_MAP is used for calculating field offsets only _ Private Structure KISO_CONTEXT_MAP ''' Additional ISO transfer flags. See \ref KISO_FLAG. Private ReadOnly Flags As KISO_FLAG ''' Specifies the frame number that the transfer should begin on (0 for ASAP). Private ReadOnly StartFrame As Integer ''' Contains the number of packets that completed with an error condition on return from the host controller driver. Private ReadOnly ErrorCount As Short ''' Specifies the number of packets that are described by the variable-length array member \c IsoPacket. Private ReadOnly NumberOfPackets As Short ''' Contains the URB Hdr.Status value on return from the host controller driver. Private ReadOnly UrbHdrStatus As Integer End Structure Private Shared ReadOnly ofsFlags As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "Flags").ToInt32() Private Shared ReadOnly ofsStartFrame As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "StartFrame").ToInt32() Private Shared ReadOnly ofsErrorCount As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "ErrorCount").ToInt32() Private Shared ReadOnly ofsNumberOfPackets As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "NumberOfPackets").ToInt32() Private Shared ReadOnly ofsUrbHdrStatus As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "UrbHdrStatus").ToInt32() ''' Additional ISO transfer flags. See \ref KISO_FLAG. Public ReadOnly Property Flags() As KISO_FLAG Get Return CType(Marshal.ReadInt32(mHandlePtr, ofsFlags), KISO_FLAG) End Get End Property ''' Specifies the frame number that the transfer should begin on (0 for ASAP). Public ReadOnly Property StartFrame() As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsStartFrame) End Get End Property ''' Contains the number of packets that completed with an error condition on return from the host controller driver. Public ReadOnly Property ErrorCount() As Short Get Return Marshal.ReadInt16(mHandlePtr, ofsErrorCount) End Get End Property ''' Specifies the number of packets that are described by the variable-length array member \c IsoPacket. Public ReadOnly Property NumberOfPackets() As Short Get Return Marshal.ReadInt16(mHandlePtr, ofsNumberOfPackets) End Get End Property ''' Contains the URB Hdr.Status value on return from the host controller driver. Public ReadOnly Property UrbHdrStatus() As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsUrbHdrStatus) End Get End Property Public Overrides Function ToString() As String Return String.Format("Flags: {0}" & vbLf & "StartFrame: {1}" & vbLf & "ErrorCount: {2}" & vbLf & "NumberOfPackets: {3}" & vbLf & "UrbHdrStatus: {4}" & vbLf, Flags.ToString(), StartFrame, ErrorCount, NumberOfPackets, UrbHdrStatus.ToString("X8") & "h") End Function End Structure ''' libusbK verson information structure. _ Public Structure KLIB_VERSION ''' Major version number. Public Major As Integer ''' Minor version number. Public Minor As Integer ''' Micro version number. Public Micro As Integer ''' Nano version number. Public Nano As Integer Public Overrides Function ToString() As String Return String.Format("Major: {0}" & vbLf & "Minor: {1}" & vbLf & "Micro: {2}" & vbLf & "Nano: {3}" & vbLf, Major, Minor, Micro, Nano) End Function End Structure ''' Common usb device information structure _ Public Structure KLST_DEV_COMMON_INFO ''' VendorID parsed from \ref KLST_DEVINFO::DeviceID Public Vid As Integer ''' ProductID parsed from \ref KLST_DEVINFO::DeviceID Public Pid As Integer ''' Composite interface number parsed from \ref KLST_DEVINFO::DeviceID. Set to \b -1 for devices that do not have the composite parent driver. Public MI As Integer ' An ID that uniquely identifies a USB device. _ Public InstanceID As String Public Overrides Function ToString() As String Return String.Format("Vid: {0}" & vbLf & "Pid: {1}" & vbLf & "MI: {2}" & vbLf & "InstanceID: {3}" & vbLf, Vid.ToString("X4") & "h", Pid.ToString("X4") & "h", MI.ToString("X2") & "h", InstanceID) End Function End Structure _ Public Structure KLST_DEVINFO_HANDLE Implements IKLIB_HANDLE Private ReadOnly mHandlePtr As IntPtr Public Sub New(Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer() As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType() As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.LSTINFOK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function ''' KLST_DEVINFO_MAP is used for calculating field offsets only _ Private Structure KLST_DEVINFO_MAP ''' Common usb device information Private ReadOnly Common As KLST_DEV_COMMON_INFO ''' Driver id this device element is using Private ReadOnly DriverID As Integer ''' Device interface GUID _ Private ReadOnly DeviceInterfaceGUID As String ''' Device instance ID. _ Private ReadOnly DeviceID As String ''' Class GUID. _ Private ReadOnly ClassGUID As String ''' Manufacturer name as specified in the INF file. _ Private ReadOnly Mfg As String ''' Device description as specified in the INF file. _ Private ReadOnly DeviceDesc As String ''' Driver service name. _ Private ReadOnly Service As String ''' Unique identifier. _ Private ReadOnly SymbolicLink As String ''' physical device filename used with the Windows \c CreateFile() _ Private ReadOnly DevicePath As String ''' libusb-win32 filter index id. Private ReadOnly LUsb0FilterIndex As Integer ''' Indicates the devices connection state. Private ReadOnly Connected As Boolean ''' Synchronization flags. (internal use only) Private ReadOnly SyncFlags As KLST_SYNC_FLAG Private ReadOnly BusNumber As Integer Private ReadOnly DeviceAddress As Integer ''' If the the device is serialized, represents the string value of \ref USB_DEVICE_DESCRIPTOR::iSerialNumber. For Devices without a \b iSerialNumber, represents the unique \b InstanceID assigned by \b Windows. _ Private ReadOnly SerialNumber As String End Structure Private Shared ReadOnly ofsCommon As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "Common").ToInt32() Private Shared ReadOnly ofsDriverID As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "DriverID").ToInt32() Private Shared ReadOnly ofsDeviceInterfaceGUID As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "DeviceInterfaceGUID").ToInt32() Private Shared ReadOnly ofsDeviceID As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "DeviceID").ToInt32() Private Shared ReadOnly ofsClassGUID As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "ClassGUID").ToInt32() Private Shared ReadOnly ofsMfg As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "Mfg").ToInt32() Private Shared ReadOnly ofsDeviceDesc As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "DeviceDesc").ToInt32() Private Shared ReadOnly ofsService As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "Service").ToInt32() Private Shared ReadOnly ofsSymbolicLink As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "SymbolicLink").ToInt32() Private Shared ReadOnly ofsDevicePath As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "DevicePath").ToInt32() Private Shared ReadOnly ofsLUsb0FilterIndex As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "LUsb0FilterIndex").ToInt32() Private Shared ReadOnly ofsConnected As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "Connected").ToInt32() Private Shared ReadOnly ofsSyncFlags As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "SyncFlags").ToInt32() Private Shared ReadOnly ofsBusNumber As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "BusNumber").ToInt32() Private Shared ReadOnly ofsDeviceAddress As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "DeviceAddress").ToInt32() Private Shared ReadOnly ofsSerialNumber As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "SerialNumber").ToInt32() ''' Common usb device information Public ReadOnly Property Common() As KLST_DEV_COMMON_INFO Get Return CType(Marshal.PtrToStructure(New IntPtr(mHandlePtr.ToInt64() + ofsCommon), GetType(KLST_DEV_COMMON_INFO)), KLST_DEV_COMMON_INFO) End Get End Property ''' Driver id this device element is using Public ReadOnly Property DriverID() As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsDriverID) End Get End Property ''' Device interface GUID Public ReadOnly Property DeviceInterfaceGUID() As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsDeviceInterfaceGUID)) End Get End Property ''' Device instance ID. Public ReadOnly Property DeviceID() As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsDeviceID)) End Get End Property ''' Class GUID. Public ReadOnly Property ClassGUID() As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsClassGUID)) End Get End Property ''' Manufacturer name as specified in the INF file. Public ReadOnly Property Mfg() As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsMfg)) End Get End Property ''' Device description as specified in the INF file. Public ReadOnly Property DeviceDesc() As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsDeviceDesc)) End Get End Property ''' Driver service name. Public ReadOnly Property Service() As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsService)) End Get End Property ''' Unique identifier. Public ReadOnly Property SymbolicLink() As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsSymbolicLink)) End Get End Property ''' physical device filename used with the Windows \c CreateFile() Public ReadOnly Property DevicePath() As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsDevicePath)) End Get End Property ''' libusb-win32 filter index id. Public ReadOnly Property LUsb0FilterIndex() As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsLUsb0FilterIndex) End Get End Property ''' Indicates the devices connection state. Public ReadOnly Property Connected() As Boolean Get Return Marshal.ReadInt32(mHandlePtr, ofsConnected) <> 0 End Get End Property ''' Synchronization flags. (internal use only) Public ReadOnly Property SyncFlags() As KLST_SYNC_FLAG Get Return CType(Marshal.ReadInt32(mHandlePtr, ofsSyncFlags), KLST_SYNC_FLAG) End Get End Property Public ReadOnly Property BusNumber() As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsBusNumber) End Get End Property Public ReadOnly Property DeviceAddress() As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsDeviceAddress) End Get End Property ''' If the the device is serialized, represents the string value of \ref USB_DEVICE_DESCRIPTOR::iSerialNumber. For Devices without a \b iSerialNumber, represents the unique \b InstanceID assigned by \b Windows. Public ReadOnly Property SerialNumber() As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsSerialNumber)) End Get End Property Public Overrides Function ToString() As String Return String.Format("DriverID: {0}" & vbLf & "DeviceInterfaceGUID: {1}" & vbLf & "DeviceID: {2}" & vbLf & "ClassGUID: {3}" & vbLf & "Mfg: {4}" & vbLf & "DeviceDesc: {5}" & vbLf & "Service: {6}" & vbLf & "SymbolicLink: {7}" & vbLf & "DevicePath: {8}" & vbLf & "LUsb0FilterIndex: {9}" & vbLf & "Connected: {10}" & vbLf & "SyncFlags: {11}" & vbLf & "BusNumber: {12}" & vbLf & "DeviceAddress: {13}" & vbLf & "SerialNumber: {14}" & vbLf, DriverID, DeviceInterfaceGUID, DeviceID, ClassGUID, Mfg, _ DeviceDesc, Service, SymbolicLink, DevicePath, LUsb0FilterIndex, Connected, _ SyncFlags.ToString(), BusNumber, DeviceAddress, SerialNumber) End Function End Structure ''' Device list/hot-plug pattern match structure. _ Public Structure KLST_PATTERN_MATCH ''' Pattern match a device instance id. _ Public DeviceID As String ''' Pattern match a device interface guid. _ Public DeviceInterfaceGUID As String ''' Pattern match a symbolic link. _ Public ClassGUID As String Public Overrides Function ToString() As String Return String.Format("DeviceID: {0}" & vbLf & "DeviceInterfaceGUID: {1}" & vbLf & "ClassGUID: {2}" & vbLf, DeviceID, DeviceInterfaceGUID, ClassGUID) End Function End Structure ''' A structure representing the standard USB device descriptor. _ Public Structure USB_DEVICE_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte ''' USB specification release number in binary-coded decimal. Public bcdUSB As UShort ''' USB-IF class code for the device Public bDeviceClass As Byte ''' USB-IF subclass code for the device Public bDeviceSubClass As Byte ''' USB-IF protocol code for the device Public bDeviceProtocol As Byte ''' Maximum packet size for control endpoint 0 Public bMaxPacketSize0 As Byte ''' USB-IF vendor ID Public idVendor As UShort ''' USB-IF product ID Public idProduct As UShort ''' Device release number in binary-coded decimal Public bcdDevice As UShort ''' Index of string descriptor describing manufacturer Public iManufacturer As Byte ''' Index of string descriptor describing product Public iProduct As Byte ''' Index of string descriptor containing device serial number Public iSerialNumber As Byte ''' Number of possible configurations Public bNumConfigurations As Byte Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & vbLf & "bDescriptorType: {1}" & vbLf & "bcdUSB: {2}" & vbLf & "bDeviceClass: {3}" & vbLf & "bDeviceSubClass: {4}" & vbLf & "bDeviceProtocol: {5}" & vbLf & "bMaxPacketSize0: {6}" & vbLf & "idVendor: {7}" & vbLf & "idProduct: {8}" & vbLf & "bcdDevice: {9}" & vbLf & "iManufacturer: {10}" & vbLf & "iProduct: {11}" & vbLf & "iSerialNumber: {12}" & vbLf & "bNumConfigurations: {13}" & vbLf, bLength, bDescriptorType.ToString("X2") & "h", bcdUSB.ToString("X4") & "h", bDeviceClass.ToString("X2") & "h", bDeviceSubClass.ToString("X2") & "h", _ bDeviceProtocol.ToString("X2") & "h", bMaxPacketSize0, idVendor.ToString("X4") & "h", idProduct.ToString("X4") & "h", bcdDevice.ToString("X4") & "h", iManufacturer, _ iProduct, iSerialNumber, bNumConfigurations) End Function End Structure ''' A structure representing the standard USB endpoint descriptor. _ Public Structure USB_ENDPOINT_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte ''' The address of the endpoint described by this descriptor. Public bEndpointAddress As Byte ''' Attributes which apply to the endpoint when it is configured using the bConfigurationValue. Public bmAttributes As Byte ''' Maximum packet size this endpoint is capable of sending/receiving. Public wMaxPacketSize As UShort ''' Interval for polling endpoint for data transfers. Public bInterval As Byte Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & vbLf & "bDescriptorType: {1}" & vbLf & "bEndpointAddress: {2}" & vbLf & "bmAttributes: {3}" & vbLf & "wMaxPacketSize: {4}" & vbLf & "bInterval: {5}" & vbLf, bLength, bDescriptorType.ToString("X2") & "h", bEndpointAddress.ToString("X2") & "h", bmAttributes.ToString("X2") & "h", wMaxPacketSize, _ bInterval) End Function End Structure ''' A structure representing the standard USB configuration descriptor. _ Public Structure USB_CONFIGURATION_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte ''' Total length of data returned for this configuration Public wTotalLength As UShort ''' Number of interfaces supported by this configuration Public bNumInterfaces As Byte ''' Identifier value for this configuration Public bConfigurationValue As Byte ''' Index of string descriptor describing this configuration Public iConfiguration As Byte ''' Configuration characteristics Public bmAttributes As Byte ''' Maximum power consumption of the USB device from this bus in this configuration when the device is fully operation. Public MaxPower As Byte Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & vbLf & "bDescriptorType: {1}" & vbLf & "wTotalLength: {2}" & vbLf & "bNumInterfaces: {3}" & vbLf & "bConfigurationValue: {4}" & vbLf & "iConfiguration: {5}" & vbLf & "bmAttributes: {6}" & vbLf & "MaxPower: {7}" & vbLf, bLength, bDescriptorType.ToString("X2") & "h", wTotalLength, bNumInterfaces, bConfigurationValue, _ iConfiguration, bmAttributes.ToString("X2") & "h", MaxPower) End Function End Structure ''' A structure representing the standard USB interface descriptor. _ Public Structure USB_INTERFACE_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte ''' Number of this interface Public bInterfaceNumber As Byte ''' Value used to select this alternate setting for this interface Public bAlternateSetting As Byte ''' Number of endpoints used by this interface (excluding the control endpoint) Public bNumEndpoints As Byte ''' USB-IF class code for this interface Public bInterfaceClass As Byte ''' USB-IF subclass code for this interface Public bInterfaceSubClass As Byte ''' USB-IF protocol code for this interface Public bInterfaceProtocol As Byte ''' Index of string descriptor describing this interface Public iInterface As Byte Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & vbLf & "bDescriptorType: {1}" & vbLf & "bInterfaceNumber: {2}" & vbLf & "bAlternateSetting: {3}" & vbLf & "bNumEndpoints: {4}" & vbLf & "bInterfaceClass: {5}" & vbLf & "bInterfaceSubClass: {6}" & vbLf & "bInterfaceProtocol: {7}" & vbLf & "iInterface: {8}" & vbLf, bLength, bDescriptorType.ToString("X2") & "h", bInterfaceNumber, bAlternateSetting, bNumEndpoints, _ bInterfaceClass.ToString("X2") & "h", bInterfaceSubClass.ToString("X2") & "h", bInterfaceProtocol.ToString("X2") & "h", iInterface) End Function End Structure ''' A structure representing the standard USB string descriptor. _ Public Structure USB_STRING_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte ''' Content of the string _ Public bString As String Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & vbLf & "bDescriptorType: {1}" & vbLf & "bString: {2}" & vbLf, bLength, bDescriptorType.ToString("X2") & "h", bString) End Function End Structure ''' A structure representing the common USB descriptor. _ Public Structure USB_COMMON_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & vbLf & "bDescriptorType: {1}" & vbLf, bLength, bDescriptorType.ToString("X2") & "h") End Function End Structure ''' Allows hardware manufacturers to define groupings of interfaces. _ Public Structure USB_INTERFACE_ASSOCIATION_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte ''' First interface number of the set of interfaces that follow this descriptor Public bFirstInterface As Byte ''' The Number of interfaces follow this descriptor that are considered "associated" Public bInterfaceCount As Byte ''' \c bInterfaceClass used for this associated interfaces Public bFunctionClass As Byte ''' \c bInterfaceSubClass used for the associated interfaces Public bFunctionSubClass As Byte ''' \c bInterfaceProtocol used for the associated interfaces Public bFunctionProtocol As Byte ''' Index of string descriptor describing the associated interfaces Public iFunction As Byte Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & vbLf & "bDescriptorType: {1}" & vbLf & "bFirstInterface: {2}" & vbLf & "bInterfaceCount: {3}" & vbLf & "bFunctionClass: {4}" & vbLf & "bFunctionSubClass: {5}" & vbLf & "bFunctionProtocol: {6}" & vbLf & "iFunction: {7}" & vbLf, bLength, bDescriptorType.ToString("X2") & "h", bFirstInterface, bInterfaceCount, bFunctionClass.ToString("X2") & "h", _ bFunctionSubClass.ToString("X2") & "h", bFunctionProtocol.ToString("X2") & "h", iFunction) End Function End Structure ''' USB core driver API information structure. _ Public Structure KUSB_DRIVER_API_INFO ''' \readonly Driver id of the driver api. Public DriverID As Integer ''' \readonly Number of valid functions contained in the driver API. Public FunctionCount As Integer Public Overrides Function ToString() As String Return String.Format("DriverID: {0}" & vbLf & "FunctionCount: {1}" & vbLf, DriverID, FunctionCount) End Function End Structure ''' Driver API function set structure. _ Public Structure KUSB_DRIVER_API ''' Driver API information. Public Info As KUSB_DRIVER_API_INFO _ Public Init As KUSB_InitDelegate _ Public Free As KUSB_FreeDelegate _ Public ClaimInterface As KUSB_ClaimInterfaceDelegate _ Public ReleaseInterface As KUSB_ReleaseInterfaceDelegate _ Public SetAltInterface As KUSB_SetAltInterfaceDelegate _ Public GetAltInterface As KUSB_GetAltInterfaceDelegate _ Public GetDescriptor As KUSB_GetDescriptorDelegate _ Public ControlTransfer As KUSB_ControlTransferDelegate _ Public SetPowerPolicy As KUSB_SetPowerPolicyDelegate _ Public GetPowerPolicy As KUSB_GetPowerPolicyDelegate _ Public SetConfiguration As KUSB_SetConfigurationDelegate _ Public GetConfiguration As KUSB_GetConfigurationDelegate _ Public ResetDevice As KUSB_ResetDeviceDelegate _ Public Initialize As KUSB_InitializeDelegate _ Public SelectInterface As KUSB_SelectInterfaceDelegate _ Public GetAssociatedInterface As KUSB_GetAssociatedInterfaceDelegate _ Public Clone As KUSB_CloneDelegate _ Public QueryInterfaceSettings As KUSB_QueryInterfaceSettingsDelegate _ Public QueryDeviceInformation As KUSB_QueryDeviceInformationDelegate _ Public SetCurrentAlternateSetting As KUSB_SetCurrentAlternateSettingDelegate _ Public GetCurrentAlternateSetting As KUSB_GetCurrentAlternateSettingDelegate _ Public QueryPipe As KUSB_QueryPipeDelegate _ Public SetPipePolicy As KUSB_SetPipePolicyDelegate _ Public GetPipePolicy As KUSB_GetPipePolicyDelegate _ Public ReadPipe As KUSB_ReadPipeDelegate _ Public WritePipe As KUSB_WritePipeDelegate _ Public ResetPipe As KUSB_ResetPipeDelegate _ Public AbortPipe As KUSB_AbortPipeDelegate _ Public FlushPipe As KUSB_FlushPipeDelegate _ Public IsoReadPipe As KUSB_IsoReadPipeDelegate _ Public IsoWritePipe As KUSB_IsoWritePipeDelegate _ Public GetCurrentFrameNumber As KUSB_GetCurrentFrameNumberDelegate _ Public GetOverlappedResult As KUSB_GetOverlappedResultDelegate _ Public GetProperty As KUSB_GetPropertyDelegate End Structure ''' Hot plug parameter structure. _ Public Structure KHOT_PARAMS ''' Hot plug event window handle to send/post messages when notifications occur. Public UserHwnd As IntPtr ''' WM_USER message start offset used when sending/posting messages, See details. Public UserMessage As Integer ''' Additional init/config parameters Public Flags As KHOT_FLAG ''' File pattern matches for restricting notifcations to a single/group or all supported usb devices. Public PatternMatch As KLST_PATTERN_MATCH ''' Hot plug event callback function invoked when notifications occur. _ Public OnHotPlug As KHOT_PLUG_CB Public Overrides Function ToString() As String Return String.Format("UserHwnd: {0}" & vbLf & "UserMessage: {1}" & vbLf & "Flags: {2}" & vbLf, UserHwnd.ToString("X16") & "h", UserMessage.ToString("X8") & "h", Flags.ToString()) End Function End Structure _ Public Structure KSTM_XFER_CONTEXT Private ReadOnly mHandlePtr As IntPtr Public Sub New(Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer() As IntPtr Get Return mHandlePtr End Get End Property ''' KSTM_XFER_CONTEXT_MAP is used for calculating field offsets only _ Private Structure KSTM_XFER_CONTEXT_MAP ''' Internal stream buffer. Private ReadOnly Buffer As IntPtr ''' Size of internal stream buffer. Private ReadOnly BufferSize As Integer ''' Number of bytes to write or number of bytes read. Private ReadOnly TransferLength As Integer ''' User defined state. Private ReadOnly UserState As IntPtr End Structure Private Shared ReadOnly ofsBuffer As Integer = Marshal.OffsetOf(GetType(KSTM_XFER_CONTEXT_MAP), "Buffer").ToInt32() Private Shared ReadOnly ofsBufferSize As Integer = Marshal.OffsetOf(GetType(KSTM_XFER_CONTEXT_MAP), "BufferSize").ToInt32() Private Shared ReadOnly ofsTransferLength As Integer = Marshal.OffsetOf(GetType(KSTM_XFER_CONTEXT_MAP), "TransferLength").ToInt32() Private Shared ReadOnly ofsUserState As Integer = Marshal.OffsetOf(GetType(KSTM_XFER_CONTEXT_MAP), "UserState").ToInt32() ''' Internal stream buffer. Public ReadOnly Property Buffer() As IntPtr Get Return Marshal.ReadIntPtr(mHandlePtr, ofsBuffer) End Get End Property ''' Size of internal stream buffer. Public ReadOnly Property BufferSize() As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsBufferSize) End Get End Property ''' Number of bytes to write or number of bytes read. Public ReadOnly Property TransferLength() As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsTransferLength) End Get End Property ''' User defined state. Public Property UserState() As IntPtr Get Return Marshal.ReadIntPtr(mHandlePtr, ofsUserState) End Get Set Marshal.WriteIntPtr(mHandlePtr, ofsUserState, value) End Set End Property Public Overrides Function ToString() As String Return String.Format("Buffer: {0}" & vbLf & "BufferSize: {1}" & vbLf & "TransferLength: {2}" & vbLf & "UserState: {3}" & vbLf, Buffer.ToString("X16") & "h", BufferSize, TransferLength, UserState.ToString("X16") & "h") End Function End Structure _ Public Structure KSTM_INFO Private ReadOnly mHandlePtr As IntPtr Public Sub New(Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer() As IntPtr Get Return mHandlePtr End Get End Property ''' KSTM_INFO_MAP is used for calculating field offsets only _ Private Structure KSTM_INFO_MAP ''' \ref KUSB_HANDLE this stream uses. Private ReadOnly UsbHandle As IntPtr ''' This parameter corresponds to the bEndpointAddress field in the endpoint descriptor. Private ReadOnly PipeID As Byte ''' Maximum transfer read/write request allowed pending. Private ReadOnly MaxPendingTransfers As Integer ''' Maximum transfer sage size. Private ReadOnly MaxTransferSize As Integer ''' Maximum number of I/O request allowed pending. Private ReadOnly MaxPendingIO As Integer ''' Populated with the endpoint descriptor for the specified \c PipeID. Private ReadOnly EndpointDescriptor As USB_ENDPOINT_DESCRIPTOR ''' Populated with the driver api for the specified \c UsbHandle. Private ReadOnly DriverAPI As KUSB_DRIVER_API ''' Populated with the device file handle for the specified \c UsbHandle. Private ReadOnly DeviceHandle As IntPtr ''' Stream handle. Private ReadOnly StreamHandle As IntPtr ''' Stream info user defined state. Private ReadOnly UserState As IntPtr End Structure Private Shared ReadOnly ofsUsbHandle As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "UsbHandle").ToInt32() Private Shared ReadOnly ofsPipeID As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "PipeID").ToInt32() Private Shared ReadOnly ofsMaxPendingTransfers As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "MaxPendingTransfers").ToInt32() Private Shared ReadOnly ofsMaxTransferSize As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "MaxTransferSize").ToInt32() Private Shared ReadOnly ofsMaxPendingIO As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "MaxPendingIO").ToInt32() Private Shared ReadOnly ofsEndpointDescriptor As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "EndpointDescriptor").ToInt32() Private Shared ReadOnly ofsDriverAPI As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "DriverAPI").ToInt32() Private Shared ReadOnly ofsDeviceHandle As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "DeviceHandle").ToInt32() Private Shared ReadOnly ofsStreamHandle As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "StreamHandle").ToInt32() Private Shared ReadOnly ofsUserState As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "UserState").ToInt32() ''' \ref KUSB_HANDLE this stream uses. Public ReadOnly Property UsbHandle() As IntPtr Get Return Marshal.ReadIntPtr(mHandlePtr, ofsUsbHandle) End Get End Property ''' This parameter corresponds to the bEndpointAddress field in the endpoint descriptor. Public ReadOnly Property PipeID() As Byte Get Return Marshal.ReadByte(mHandlePtr, ofsPipeID) End Get End Property ''' Maximum transfer read/write request allowed pending. Public ReadOnly Property MaxPendingTransfers() As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsMaxPendingTransfers) End Get End Property ''' Maximum transfer sage size. Public ReadOnly Property MaxTransferSize() As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsMaxTransferSize) End Get End Property ''' Maximum number of I/O request allowed pending. Public ReadOnly Property MaxPendingIO() As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsMaxPendingIO) End Get End Property ''' Populated with the endpoint descriptor for the specified \c PipeID. Public ReadOnly Property EndpointDescriptor() As USB_ENDPOINT_DESCRIPTOR Get Return CType(Marshal.PtrToStructure(New IntPtr(mHandlePtr.ToInt64() + ofsEndpointDescriptor), GetType(USB_ENDPOINT_DESCRIPTOR)), USB_ENDPOINT_DESCRIPTOR) End Get End Property ''' Populated with the driver api for the specified \c UsbHandle. Public ReadOnly Property DriverAPI() As KUSB_DRIVER_API Get Return CType(Marshal.PtrToStructure(New IntPtr(mHandlePtr.ToInt64() + ofsDriverAPI), GetType(KUSB_DRIVER_API)), KUSB_DRIVER_API) End Get End Property ''' Populated with the device file handle for the specified \c UsbHandle. Public ReadOnly Property DeviceHandle() As IntPtr Get Return Marshal.ReadIntPtr(mHandlePtr, ofsDeviceHandle) End Get End Property ''' Stream handle. Public ReadOnly Property StreamHandle() As IntPtr Get Return Marshal.ReadIntPtr(mHandlePtr, ofsStreamHandle) End Get End Property ''' Stream info user defined state. Public Property UserState() As IntPtr Get Return Marshal.ReadIntPtr(mHandlePtr, ofsUserState) End Get Set Marshal.WriteIntPtr(mHandlePtr, ofsUserState, value) End Set End Property Public Overrides Function ToString() As String Return String.Format("UsbHandle: {0}" & vbLf & "PipeID: {1}" & vbLf & "MaxPendingTransfers: {2}" & vbLf & "MaxTransferSize: {3}" & vbLf & "MaxPendingIO: {4}" & vbLf & "DeviceHandle: {5}" & vbLf & "StreamHandle: {6}" & vbLf & "UserState: {7}" & vbLf, UsbHandle.ToString("X16") & "h", PipeID.ToString("X2") & "h", MaxPendingTransfers, MaxTransferSize, MaxPendingIO, _ DeviceHandle.ToString("X16") & "h", StreamHandle.ToString("X16") & "h", UserState.ToString("X16") & "h") End Function End Structure ''' Stream callback structure. _ Public Structure KSTM_CALLBACK ''' Executed when a transfer error occurs. _ Public [Error] As KSTM_ERROR_CB ''' Executed to submit a transfer. _ Public Submit As KSTM_SUBMIT_CB ''' Executed when a valid transfer completes. _ Public Complete As KSTM_COMPLETE_CB ''' Executed for every transfer context when the stream is started with \ref StmK_Start. _ Public Started As KSTM_STARTED_CB ''' Executed for every transfer context when the stream is stopped with \ref StmK_Stop. _ Public Stopped As KSTM_STOPPED_CB ''' Executed immediately after a transfer completes. _ Public BeforeComplete As KSTM_BEFORE_COMPLETE_CB End Structure #End Region #Region "Delegates" _ Public Delegate Function KLIB_HANDLE_CLEANUP_CB(<[In]> Handle As IntPtr, HandleType As KLIB_HANDLE_TYPE, UserContext As IntPtr) As Integer _ Public Delegate Function KISO_ENUM_PACKETS_CB(PacketIndex As Integer, <[In]> ByRef IsoPacket As KISO_PACKET, UserState As IntPtr) As Boolean _ Public Delegate Function KLST_ENUM_DEVINFO_CB(<[In]> DeviceList As KLST_HANDLE, <[In]> DeviceInfo As KLST_DEVINFO_HANDLE, Context As IntPtr) As Boolean _ Public Delegate Function KUSB_InitDelegate( ByRef InterfaceHandle As KUSB_HANDLE, <[In]> DevInfo As KLST_DEVINFO_HANDLE) As Boolean _ Public Delegate Function KUSB_FreeDelegate(<[In]> InterfaceHandle As KUSB_HANDLE) As Boolean _ Public Delegate Function KUSB_ClaimInterfaceDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, NumberOrIndex As Byte, IsIndex As Boolean) As Boolean _ Public Delegate Function KUSB_ReleaseInterfaceDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, NumberOrIndex As Byte, IsIndex As Boolean) As Boolean _ Public Delegate Function KUSB_SetAltInterfaceDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, NumberOrIndex As Byte, IsIndex As Boolean, AltSettingNumber As Byte) As Boolean _ Public Delegate Function KUSB_GetAltInterfaceDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, NumberOrIndex As Byte, IsIndex As Boolean, ByRef AltSettingNumber As Byte) As Boolean _ Public Delegate Function KUSB_GetDescriptorDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, DescriptorType As Byte, Index As Byte, LanguageID As UShort, Buffer As IntPtr, BufferLength As Integer, _ ByRef LengthTransferred As Integer) As Boolean _ Public Delegate Function KUSB_ControlTransferDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, SetupPacket As WINUSB_SETUP_PACKET, Buffer As IntPtr, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As IntPtr) As Boolean _ Public Delegate Function KUSB_SetPowerPolicyDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, PolicyType As Integer, ValueLength As Integer, Value As IntPtr) As Boolean _ Public Delegate Function KUSB_GetPowerPolicyDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, PolicyType As Integer, ByRef ValueLength As Integer, Value As IntPtr) As Boolean _ Public Delegate Function KUSB_SetConfigurationDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, ConfigurationNumber As Byte) As Boolean _ Public Delegate Function KUSB_GetConfigurationDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, ByRef ConfigurationNumber As Byte) As Boolean _ Public Delegate Function KUSB_ResetDeviceDelegate(<[In]> InterfaceHandle As KUSB_HANDLE) As Boolean _ Public Delegate Function KUSB_InitializeDelegate(DeviceHandle As IntPtr, ByRef InterfaceHandle As KUSB_HANDLE) As Boolean _ Public Delegate Function KUSB_SelectInterfaceDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, NumberOrIndex As Byte, IsIndex As Boolean) As Boolean _ Public Delegate Function KUSB_GetAssociatedInterfaceDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, AssociatedInterfaceIndex As Byte, ByRef AssociatedInterfaceHandle As KUSB_HANDLE) As Boolean _ Public Delegate Function KUSB_CloneDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, ByRef DstInterfaceHandle As KUSB_HANDLE) As Boolean _ Public Delegate Function KUSB_QueryInterfaceSettingsDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, AltSettingIndex As Byte, ByRef UsbAltInterfaceDescriptor As USB_INTERFACE_DESCRIPTOR) As Boolean _ Public Delegate Function KUSB_QueryDeviceInformationDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, InformationType As Integer, ByRef BufferLength As Integer, Buffer As IntPtr) As Boolean _ Public Delegate Function KUSB_SetCurrentAlternateSettingDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, AltSettingNumber As Byte) As Boolean _ Public Delegate Function KUSB_GetCurrentAlternateSettingDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, ByRef AltSettingNumber As Byte) As Boolean _ Public Delegate Function KUSB_QueryPipeDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, AltSettingNumber As Byte, PipeIndex As Byte, ByRef PipeInformation As WINUSB_PIPE_INFORMATION) As Boolean _ Public Delegate Function KUSB_SetPipePolicyDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, PipeID As Byte, PolicyType As Integer, ValueLength As Integer, Value As IntPtr) As Boolean _ Public Delegate Function KUSB_GetPipePolicyDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, PipeID As Byte, PolicyType As Integer, ByRef ValueLength As Integer, Value As IntPtr) As Boolean _ Public Delegate Function KUSB_ReadPipeDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, PipeID As Byte, Buffer As IntPtr, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As IntPtr) As Boolean _ Public Delegate Function KUSB_WritePipeDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, PipeID As Byte, Buffer As IntPtr, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As IntPtr) As Boolean _ Public Delegate Function KUSB_ResetPipeDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, PipeID As Byte) As Boolean _ Public Delegate Function KUSB_AbortPipeDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, PipeID As Byte) As Boolean _ Public Delegate Function KUSB_FlushPipeDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, PipeID As Byte) As Boolean _ Public Delegate Function KUSB_IsoReadPipeDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, PipeID As Byte, Buffer As IntPtr, BufferLength As Integer, Overlapped As IntPtr, <[In]> IsoContext As KISO_CONTEXT) As Boolean _ Public Delegate Function KUSB_IsoWritePipeDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, PipeID As Byte, Buffer As IntPtr, BufferLength As Integer, Overlapped As IntPtr, <[In]> IsoContext As KISO_CONTEXT) As Boolean _ Public Delegate Function KUSB_GetCurrentFrameNumberDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, ByRef FrameNumber As Integer) As Boolean _ Public Delegate Function KUSB_GetOverlappedResultDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, Overlapped As IntPtr, ByRef lpNumberOfBytesTransferred As Integer, bWait As Boolean) As Boolean _ Public Delegate Function KUSB_GetPropertyDelegate(<[In]> InterfaceHandle As KUSB_HANDLE, PropertyType As KUSB_PROPERTY, ByRef PropertySize As Integer, Value As IntPtr) As Boolean _ Public Delegate Sub KHOT_PLUG_CB(<[In]> HotHandle As KHOT_HANDLE, <[In]> DeviceInfo As KLST_DEVINFO_HANDLE, PlugType As KLST_SYNC_FLAG) _ Public Delegate Function KSTM_ERROR_CB(<[In]> StreamInfo As KSTM_INFO, <[In]> XferContext As KSTM_XFER_CONTEXT, XferContextIndex As Integer, ErrorCode As Integer) As Integer _ Public Delegate Function KSTM_SUBMIT_CB(<[In]> StreamInfo As KSTM_INFO, <[In]> XferContext As KSTM_XFER_CONTEXT, XferContextIndex As Integer, Overlapped As IntPtr) As Integer _ Public Delegate Function KSTM_STARTED_CB(<[In]> StreamInfo As KSTM_INFO, <[In]> XferContext As KSTM_XFER_CONTEXT, XferContextIndex As Integer) As Integer _ Public Delegate Function KSTM_STOPPED_CB(<[In]> StreamInfo As KSTM_INFO, <[In]> XferContext As KSTM_XFER_CONTEXT, XferContextIndex As Integer) As Integer _ Public Delegate Function KSTM_COMPLETE_CB(<[In]> StreamInfo As KSTM_INFO, <[In]> XferContext As KSTM_XFER_CONTEXT, XferContextIndex As Integer, ErrorCode As Integer) As Integer _ Public Delegate Function KSTM_BEFORE_COMPLETE_CB(<[In]> StreamInfo As KSTM_INFO, <[In]> XferContext As KSTM_XFER_CONTEXT, XferContextIndex As Integer, ByRef ErrorCode As Integer) As KSTM_COMPLETE_RESULT #End Region Public Class LstK Implements IDisposable Protected mHandleStruct As KLST_HANDLE Protected mbDisposed As Boolean Protected Sub New() End Sub #Region "IDisposable Members" ''' Explicitly closes and frees the handle. Public Overridable Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub #End Region Protected Overrides Sub Finalize() Try Dispose(False) Finally MyBase.Finalize() End Try End Sub Protected Overridable Sub Dispose(disposing As Boolean) If Not mbDisposed Then If mHandleStruct.Pointer <> IntPtr.Zero Then AllKFunctions.LstK_Free(mHandleStruct) Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", [GetType]().Name, mHandleStruct.Pointer.ToInt64(), disposing) Else Debug.Print("{0} Dispose: [WARNING] Handle is null", [GetType]().Name) End If mHandleStruct = New KLST_HANDLE(IntPtr.Zero) mbDisposed = True End If End Sub ''' Initializes a new usb device list containing all supported devices. Protected Function Init(Flags As KLST_FLAG) As Boolean Dim success As Boolean = AllKFunctions.LstK_Init(mHandleStruct, Flags) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function ''' Initializes a new usb device list containing only devices matching a specific class GUID. Protected Function InitEx(Flags As KLST_FLAG, ByRef PatternMatch As KLST_PATTERN_MATCH) As Boolean Dim success As Boolean = AllKFunctions.LstK_InitEx(mHandleStruct, Flags, PatternMatch) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function #Region "Public Members" ''' Initializes a new usb device list containing all supported devices. Public Sub New(Flags As KLST_FLAG) Dim success As Boolean = AllKFunctions.LstK_Init(mHandleStruct, Flags) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Initializes a new usb device list containing only devices matching a specific class GUID. Public Sub New(Flags As KLST_FLAG, ByRef PatternMatch As KLST_PATTERN_MATCH) Dim success As Boolean = AllKFunctions.LstK_InitEx(mHandleStruct, Flags, PatternMatch) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Counts the number of device info elements in a device list. Public Overridable Function Count(ByRef Count As Integer) As Boolean Return AllKFunctions.LstK_Count(mHandleStruct, Count) End Function ''' Gets the \ref KLST_DEVINFO element for the current position. Public Overridable Function Current(ByRef DeviceInfo As KLST_DEVINFO_HANDLE) As Boolean Return AllKFunctions.LstK_Current(mHandleStruct, DeviceInfo) End Function ''' Enumerates \ref KLST_DEVINFO elements of a \ref KLST_HANDLE. Public Overridable Function Enumerate(EnumDevListCB As KLST_ENUM_DEVINFO_CB, Context As IntPtr) As Boolean Return AllKFunctions.LstK_Enumerate(mHandleStruct, EnumDevListCB, Context) End Function ''' Find a device by vendor and product id Public Overridable Function FindByVidPid(Vid As Integer, Pid As Integer, ByRef DeviceInfo As KLST_DEVINFO_HANDLE) As Boolean Return AllKFunctions.LstK_FindByVidPid(mHandleStruct, Vid, Pid, DeviceInfo) End Function ''' Calls the dispose method. Public Overridable Sub Free() Dispose() End Sub ''' Gets the handle class structure. Public ReadOnly Property Handle() As KLST_HANDLE Get Return mHandleStruct End Get End Property ''' Advances the device list current \ref KLST_DEVINFO position. Public Overridable Function MoveNext(ByRef DeviceInfo As KLST_DEVINFO_HANDLE) As Boolean Return AllKFunctions.LstK_MoveNext(mHandleStruct, DeviceInfo) End Function ''' Sets the device list to its initial position, which is before the first element in the list. Public Overridable Sub MoveReset() AllKFunctions.LstK_MoveReset(mHandleStruct) End Sub #End Region End Class Public Class HotK Implements IDisposable Protected mHandleStruct As KHOT_HANDLE Protected mbDisposed As Boolean Protected Sub New() End Sub #Region "IDisposable Members" ''' Explicitly closes and frees the handle. Public Overridable Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub #End Region Protected Overrides Sub Finalize() Try Dispose(False) Finally MyBase.Finalize() End Try End Sub Protected Overridable Sub Dispose(disposing As Boolean) If Not mbDisposed Then If mHandleStruct.Pointer <> IntPtr.Zero Then AllKFunctions.HotK_Free(mHandleStruct) Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", [GetType]().Name, mHandleStruct.Pointer.ToInt64(), disposing) Else Debug.Print("{0} Dispose: [WARNING] Handle is null", [GetType]().Name) End If mHandleStruct = New KHOT_HANDLE(IntPtr.Zero) mbDisposed = True End If End Sub ''' Creates a new hot-plug handle for USB device arrival/removal event monitoring. Protected Function Init(ByRef InitParams As KHOT_PARAMS) As Boolean Dim success As Boolean = AllKFunctions.HotK_Init(mHandleStruct, InitParams) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function #Region "Public Members" ''' Creates a new hot-plug handle for USB device arrival/removal event monitoring. Public Sub New(ByRef InitParams As KHOT_PARAMS) Dim success As Boolean = AllKFunctions.HotK_Init(mHandleStruct, InitParams) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Calls the dispose method. Public Overridable Sub Free() Dispose() End Sub ''' Frees all hot-plug handles initialized with \ref HotK_Init. Public Overridable Sub FreeAll() AllKFunctions.HotK_FreeAll() End Sub ''' Gets the handle class structure. Public ReadOnly Property Handle() As KHOT_HANDLE Get Return mHandleStruct End Get End Property #End Region End Class Public Class UsbK Implements IDisposable Protected driverAPI As KUSB_DRIVER_API Protected mHandleStruct As KUSB_HANDLE Protected mbDisposed As Boolean Protected Sub New() End Sub #Region "IDisposable Members" ''' Explicitly closes and frees the handle. Public Overridable Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub #End Region Protected Overrides Sub Finalize() Try Dispose(False) Finally MyBase.Finalize() End Try End Sub Protected Overridable Sub Dispose(disposing As Boolean) If Not mbDisposed Then If mHandleStruct.Pointer <> IntPtr.Zero Then AllKFunctions.UsbK_Free(mHandleStruct) Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", [GetType]().Name, mHandleStruct.Pointer.ToInt64(), disposing) Else Debug.Print("{0} Dispose: [WARNING] Handle is null", [GetType]().Name) End If mHandleStruct = New KUSB_HANDLE(IntPtr.Zero) mbDisposed = True End If End Sub ''' Creates/opens a libusbK interface handle from the device list. This is a preferred method. Protected Function Init(DevInfo As KLST_DEVINFO_HANDLE) As Boolean Dim success As Boolean = AllKFunctions.LibK_LoadDriverAPI(driverAPI, DevInfo.DriverID) If Not success Then Throw New Exception(String.Format("{0} failed loading Driver API. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If success = driverAPI.Init(mHandleStruct, DevInfo) If Not success Then Throw New Exception(String.Format("{0} failed initializing usb device. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function ''' Creates a libusbK handle for the device specified by a file handle. Protected Function Initialize(DeviceHandle As IntPtr, driverID As KUSB_DRVID) As Boolean Dim success As Boolean = AllKFunctions.LibK_LoadDriverAPI(driverAPI, CInt(driverID)) If Not success Then Throw New Exception(String.Format("{0} failed loading Driver API. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If success = driverAPI.Initialize(DeviceHandle, mHandleStruct) If Not success Then Throw New Exception(String.Format("{0} failed initializing usb device. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function #Region "Public Members" ''' Creates/opens a libusbK interface handle from the device list. This is a preferred method. Public Sub New(DevInfo As KLST_DEVINFO_HANDLE) Dim success As Boolean = AllKFunctions.LibK_LoadDriverAPI(driverAPI, DevInfo.DriverID) If Not success Then Throw New Exception(String.Format("{0} failed loading Driver API. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If success = driverAPI.Init(mHandleStruct, DevInfo) If Not success Then Throw New Exception(String.Format("{0} failed initializing usb device. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Creates a libusbK handle for the device specified by a file handle. Public Sub New(DeviceHandle As IntPtr, driverID As KUSB_DRVID) Dim success As Boolean = AllKFunctions.LibK_LoadDriverAPI(driverAPI, CInt(driverID)) If Not success Then Throw New Exception(String.Format("{0} failed loading Driver API. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If success = driverAPI.Initialize(DeviceHandle, mHandleStruct) If Not success Then Throw New Exception(String.Format("{0} failed initializing usb device. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Aborts all of the pending transfers for a pipe. Public Overridable Function AbortPipe(PipeID As Byte) As Boolean Return driverAPI.AbortPipe(mHandleStruct, PipeID) End Function ''' Claims the specified interface by number or index. Public Overridable Function ClaimInterface(NumberOrIndex As Byte, IsIndex As Boolean) As Boolean Return driverAPI.ClaimInterface(mHandleStruct, NumberOrIndex, IsIndex) End Function ''' Clones the specified interface handle. Public Overridable Function Clone(ByRef DstInterfaceHandle As KUSB_HANDLE) As Boolean Return driverAPI.Clone(mHandleStruct, DstInterfaceHandle) End Function ''' Transmits control data over a default control endpoint. Public Overridable Function ControlTransfer(SetupPacket As WINUSB_SETUP_PACKET, Buffer As IntPtr, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As IntPtr) As Boolean Return driverAPI.ControlTransfer(mHandleStruct, SetupPacket, Buffer, BufferLength, LengthTransferred, Overlapped) End Function ''' Transmits control data over a default control endpoint. Public Overridable Function ControlTransfer(SetupPacket As WINUSB_SETUP_PACKET, Buffer As Array, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As IntPtr) As Boolean Return driverAPI.ControlTransfer(mHandleStruct, SetupPacket, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped) End Function ''' Transmits control data over a default control endpoint. Public Overridable Function ControlTransfer(SetupPacket As WINUSB_SETUP_PACKET, Buffer As Array, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.ControlTransfer(mHandleStruct, SetupPacket, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped.Pointer) End Function ''' Transmits control data over a default control endpoint. Public Overridable Function ControlTransfer(SetupPacket As WINUSB_SETUP_PACKET, Buffer As IntPtr, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.ControlTransfer(mHandleStruct, SetupPacket, Buffer, BufferLength, LengthTransferred, Overlapped.Pointer) End Function ''' Discards any data that is cached in a pipe. Public Overridable Function FlushPipe(PipeID As Byte) As Boolean Return driverAPI.FlushPipe(mHandleStruct, PipeID) End Function ''' Calls the dispose method. Public Overridable Sub Free() Dispose() End Sub ''' Gets the alternate setting for the specified interface. Public Overridable Function GetAltInterface(NumberOrIndex As Byte, IsIndex As Boolean, ByRef AltSettingNumber As Byte) As Boolean Return driverAPI.GetAltInterface(mHandleStruct, NumberOrIndex, IsIndex, AltSettingNumber) End Function ''' Retrieves a handle for an associated interface. Public Overridable Function GetAssociatedInterface(AssociatedInterfaceIndex As Byte, ByRef AssociatedInterfaceHandle As KUSB_HANDLE) As Boolean Return driverAPI.GetAssociatedInterface(mHandleStruct, AssociatedInterfaceIndex, AssociatedInterfaceHandle) End Function ''' Gets the device current configuration number. Public Overridable Function GetConfiguration(ByRef ConfigurationNumber As Byte) As Boolean Return driverAPI.GetConfiguration(mHandleStruct, ConfigurationNumber) End Function ''' Gets the current alternate interface setting for an interface. Public Overridable Function GetCurrentAlternateSetting(ByRef AltSettingNumber As Byte) As Boolean Return driverAPI.GetCurrentAlternateSetting(mHandleStruct, AltSettingNumber) End Function ''' Retrieves the current USB frame number. Public Overridable Function GetCurrentFrameNumber(ByRef FrameNumber As Integer) As Boolean Return driverAPI.GetCurrentFrameNumber(mHandleStruct, FrameNumber) End Function ''' Gets the requested descriptor. This is a synchronous operation. Public Overridable Function GetDescriptor(DescriptorType As Byte, Index As Byte, LanguageID As Integer, Buffer As IntPtr, BufferLength As Integer, ByRef LengthTransferred As Integer) As Boolean Return driverAPI.GetDescriptor(mHandleStruct, DescriptorType, Index, CUShort(LanguageID), Buffer, BufferLength, _ LengthTransferred) End Function ''' Gets the requested descriptor. This is a synchronous operation. Public Overridable Function GetDescriptor(DescriptorType As Byte, Index As Byte, LanguageID As Integer, Buffer As Array, BufferLength As Integer, ByRef LengthTransferred As Integer) As Boolean Return driverAPI.GetDescriptor(mHandleStruct, DescriptorType, Index, CUShort(LanguageID), Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, _ LengthTransferred) End Function ''' Retrieves the results of an overlapped operation on the specified libusbK handle. Public Overridable Function GetOverlappedResult(Overlapped As IntPtr, ByRef lpNumberOfBytesTransferred As Integer, bWait As Boolean) As Boolean Return driverAPI.GetOverlappedResult(mHandleStruct, Overlapped, lpNumberOfBytesTransferred, bWait) End Function ''' Retrieves the results of an overlapped operation on the specified libusbK handle. Public Overridable Function GetOverlappedResult(Overlapped As KOVL_HANDLE, ByRef lpNumberOfBytesTransferred As Integer, bWait As Boolean) As Boolean Return driverAPI.GetOverlappedResult(mHandleStruct, Overlapped.Pointer, lpNumberOfBytesTransferred, bWait) End Function ''' Gets the policy for a specific pipe (endpoint). Public Overridable Function GetPipePolicy(PipeID As Byte, PolicyType As Integer, ByRef ValueLength As Integer, Value As IntPtr) As Boolean Return driverAPI.GetPipePolicy(mHandleStruct, PipeID, PolicyType, ValueLength, Value) End Function ''' Gets the policy for a specific pipe (endpoint). Public Overridable Function GetPipePolicy(PipeID As Byte, PolicyType As Integer, ByRef ValueLength As Integer, Value As Array) As Boolean Return driverAPI.GetPipePolicy(mHandleStruct, PipeID, PolicyType, ValueLength, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0)) End Function ''' Gets the power policy for a device. Public Overridable Function GetPowerPolicy(PolicyType As Integer, ByRef ValueLength As Integer, Value As IntPtr) As Boolean Return driverAPI.GetPowerPolicy(mHandleStruct, PolicyType, ValueLength, Value) End Function ''' Gets the power policy for a device. Public Overridable Function GetPowerPolicy(PolicyType As Integer, ByRef ValueLength As Integer, Value As Array) As Boolean Return driverAPI.GetPowerPolicy(mHandleStruct, PolicyType, ValueLength, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0)) End Function ''' Gets a USB device (driver specific) property from usb handle. Public Overridable Function GetProperty(PropertyType As KUSB_PROPERTY, ByRef PropertySize As Integer, Value As IntPtr) As Boolean Return driverAPI.GetProperty(mHandleStruct, PropertyType, PropertySize, Value) End Function ''' Gets a USB device (driver specific) property from usb handle. Public Overridable Function GetProperty(PropertyType As KUSB_PROPERTY, ByRef PropertySize As Integer, Value As Array) As Boolean Return driverAPI.GetProperty(mHandleStruct, PropertyType, PropertySize, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0)) End Function ''' Gets the handle class structure. Public ReadOnly Property Handle() As KUSB_HANDLE Get Return mHandleStruct End Get End Property ''' Reads from an isochronous pipe. Public Overridable Function IsoReadPipe(PipeID As Byte, Buffer As IntPtr, BufferLength As Integer, Overlapped As IntPtr, IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoReadPipe(mHandleStruct, PipeID, Buffer, BufferLength, Overlapped, IsoContext) End Function ''' Reads from an isochronous pipe. Public Overridable Function IsoReadPipe(PipeID As Byte, Buffer As Array, BufferLength As Integer, Overlapped As IntPtr, IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoReadPipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, Overlapped, IsoContext) End Function ''' Reads from an isochronous pipe. Public Overridable Function IsoReadPipe(PipeID As Byte, Buffer As Array, BufferLength As Integer, Overlapped As KOVL_HANDLE, IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoReadPipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, Overlapped.Pointer, IsoContext) End Function ''' Reads from an isochronous pipe. Public Overridable Function IsoReadPipe(PipeID As Byte, Buffer As IntPtr, BufferLength As Integer, Overlapped As KOVL_HANDLE, IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoReadPipe(mHandleStruct, PipeID, Buffer, BufferLength, Overlapped.Pointer, IsoContext) End Function ''' Writes to an isochronous pipe. Public Overridable Function IsoWritePipe(PipeID As Byte, Buffer As IntPtr, BufferLength As Integer, Overlapped As IntPtr, IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoWritePipe(mHandleStruct, PipeID, Buffer, BufferLength, Overlapped, IsoContext) End Function ''' Writes to an isochronous pipe. Public Overridable Function IsoWritePipe(PipeID As Byte, Buffer As Array, BufferLength As Integer, Overlapped As IntPtr, IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoWritePipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, Overlapped, IsoContext) End Function ''' Writes to an isochronous pipe. Public Overridable Function IsoWritePipe(PipeID As Byte, Buffer As Array, BufferLength As Integer, Overlapped As KOVL_HANDLE, IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoWritePipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, Overlapped.Pointer, IsoContext) End Function ''' Writes to an isochronous pipe. Public Overridable Function IsoWritePipe(PipeID As Byte, Buffer As IntPtr, BufferLength As Integer, Overlapped As KOVL_HANDLE, IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoWritePipe(mHandleStruct, PipeID, Buffer, BufferLength, Overlapped.Pointer, IsoContext) End Function ''' Retrieves information about the physical device that is associated with a libusbK handle. Public Overridable Function QueryDeviceInformation(InformationType As Integer, ByRef BufferLength As Integer, Buffer As IntPtr) As Boolean Return driverAPI.QueryDeviceInformation(mHandleStruct, InformationType, BufferLength, Buffer) End Function ''' Retrieves the interface descriptor for the specified alternate interface settings for a particular interface handle. Public Overridable Function QueryInterfaceSettings(AltSettingIndex As Byte, ByRef UsbAltInterfaceDescriptor As USB_INTERFACE_DESCRIPTOR) As Boolean Return driverAPI.QueryInterfaceSettings(mHandleStruct, AltSettingIndex, UsbAltInterfaceDescriptor) End Function ''' Retrieves information about a pipe that is associated with an interface. Public Overridable Function QueryPipe(AltSettingNumber As Byte, PipeIndex As Byte, ByRef PipeInformation As WINUSB_PIPE_INFORMATION) As Boolean Return driverAPI.QueryPipe(mHandleStruct, AltSettingNumber, PipeIndex, PipeInformation) End Function ''' Reads data from the specified pipe. Public Overridable Function ReadPipe(PipeID As Byte, Buffer As IntPtr, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As IntPtr) As Boolean Return driverAPI.ReadPipe(mHandleStruct, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped) End Function ''' Reads data from the specified pipe. Public Overridable Function ReadPipe(PipeID As Byte, Buffer As Array, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As IntPtr) As Boolean Return driverAPI.ReadPipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped) End Function ''' Reads data from the specified pipe. Public Overridable Function ReadPipe(PipeID As Byte, Buffer As Array, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.ReadPipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped.Pointer) End Function ''' Reads data from the specified pipe. Public Overridable Function ReadPipe(PipeID As Byte, Buffer As IntPtr, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.ReadPipe(mHandleStruct, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped.Pointer) End Function ''' Releases the specified interface by number or index. Public Overridable Function ReleaseInterface(NumberOrIndex As Byte, IsIndex As Boolean) As Boolean Return driverAPI.ReleaseInterface(mHandleStruct, NumberOrIndex, IsIndex) End Function ''' Resets the usb device of the specified interface handle. (port cycle). Public Overridable Function ResetDevice() As Boolean Return driverAPI.ResetDevice(mHandleStruct) End Function ''' Resets the data toggle and clears the stall condition on a pipe. Public Overridable Function ResetPipe(PipeID As Byte) As Boolean Return driverAPI.ResetPipe(mHandleStruct, PipeID) End Function ''' Selects the specified interface by number or index as the current interface. Public Overridable Function SelectInterface(NumberOrIndex As Byte, IsIndex As Boolean) As Boolean Return driverAPI.SelectInterface(mHandleStruct, NumberOrIndex, IsIndex) End Function ''' Sets the alternate setting of the specified interface. Public Overridable Function SetAltInterface(NumberOrIndex As Byte, IsIndex As Boolean, AltSettingNumber As Byte) As Boolean Return driverAPI.SetAltInterface(mHandleStruct, NumberOrIndex, IsIndex, AltSettingNumber) End Function ''' Sets the device configuration number. Public Overridable Function SetConfiguration(ConfigurationNumber As Byte) As Boolean Return driverAPI.SetConfiguration(mHandleStruct, ConfigurationNumber) End Function ''' Sets the alternate setting of an interface. Public Overridable Function SetCurrentAlternateSetting(AltSettingNumber As Byte) As Boolean Return driverAPI.SetCurrentAlternateSetting(mHandleStruct, AltSettingNumber) End Function ''' Sets the policy for a specific pipe associated with an endpoint on the device. This is a synchronous operation. Public Overridable Function SetPipePolicy(PipeID As Byte, PolicyType As Integer, ValueLength As Integer, Value As IntPtr) As Boolean Return driverAPI.SetPipePolicy(mHandleStruct, PipeID, PolicyType, ValueLength, Value) End Function ''' Sets the policy for a specific pipe associated with an endpoint on the device. This is a synchronous operation. Public Overridable Function SetPipePolicy(PipeID As Byte, PolicyType As Integer, ValueLength As Integer, Value As Array) As Boolean Return driverAPI.SetPipePolicy(mHandleStruct, PipeID, PolicyType, ValueLength, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0)) End Function ''' Sets the power policy for a device. Public Overridable Function SetPowerPolicy(PolicyType As Integer, ValueLength As Integer, Value As IntPtr) As Boolean Return driverAPI.SetPowerPolicy(mHandleStruct, PolicyType, ValueLength, Value) End Function ''' Sets the power policy for a device. Public Overridable Function SetPowerPolicy(PolicyType As Integer, ValueLength As Integer, Value As Array) As Boolean Return driverAPI.SetPowerPolicy(mHandleStruct, PolicyType, ValueLength, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0)) End Function ''' Writes data to a pipe. Public Overridable Function WritePipe(PipeID As Byte, Buffer As IntPtr, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As IntPtr) As Boolean Return driverAPI.WritePipe(mHandleStruct, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped) End Function ''' Writes data to a pipe. Public Overridable Function WritePipe(PipeID As Byte, Buffer As Array, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As IntPtr) As Boolean Return driverAPI.WritePipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped) End Function ''' Writes data to a pipe. Public Overridable Function WritePipe(PipeID As Byte, Buffer As Array, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.WritePipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped.Pointer) End Function ''' Writes data to a pipe. Public Overridable Function WritePipe(PipeID As Byte, Buffer As IntPtr, BufferLength As Integer, ByRef LengthTransferred As Integer, Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.WritePipe(mHandleStruct, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped.Pointer) End Function #End Region End Class Public Class OvlK Implements IDisposable Protected mHandleStruct As KOVL_POOL_HANDLE Protected mbDisposed As Boolean Protected Sub New() End Sub #Region "IDisposable Members" ''' Explicitly closes and frees the handle. Public Overridable Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub #End Region Protected Overrides Sub Finalize() Try Dispose(False) Finally MyBase.Finalize() End Try End Sub Protected Overridable Sub Dispose(disposing As Boolean) If Not mbDisposed Then If mHandleStruct.Pointer <> IntPtr.Zero Then AllKFunctions.OvlK_Free(mHandleStruct) Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", [GetType]().Name, mHandleStruct.Pointer.ToInt64(), disposing) Else Debug.Print("{0} Dispose: [WARNING] Handle is null", [GetType]().Name) End If mHandleStruct = New KOVL_POOL_HANDLE(IntPtr.Zero) mbDisposed = True End If End Sub ''' Creates a new overlapped pool. Protected Function Init(UsbHandle As KUSB_HANDLE, MaxOverlappedCount As Integer, Flags As KOVL_POOL_FLAG) As Boolean Dim success As Boolean = AllKFunctions.OvlK_Init(mHandleStruct, UsbHandle, MaxOverlappedCount, Flags) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function #Region "Public Members" ''' Creates a new overlapped pool. Public Sub New(UsbHandle As KUSB_HANDLE, MaxOverlappedCount As Integer, Flags As KOVL_POOL_FLAG) Dim success As Boolean = AllKFunctions.OvlK_Init(mHandleStruct, UsbHandle, MaxOverlappedCount, Flags) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Gets a preallocated \c OverlappedK structure from the specified/default pool. Public Overridable Function Acquire(ByRef OverlappedK As KOVL_HANDLE) As Boolean Return AllKFunctions.OvlK_Acquire(OverlappedK, mHandleStruct) End Function ''' Calls the dispose method. Public Overridable Sub Free() Dispose() End Sub ''' Returns the internal event handle used to signal IO operations. Public Overridable Function GetEventHandle(OverlappedK As KOVL_HANDLE) As IntPtr Return AllKFunctions.OvlK_GetEventHandle(OverlappedK) End Function ''' Gets the handle class structure. Public ReadOnly Property Handle() As KOVL_POOL_HANDLE Get Return mHandleStruct End Get End Property ''' Checks for i/o completion; returns immediately. (polling) Public Overridable Function IsComplete(OverlappedK As KOVL_HANDLE) As Boolean Return AllKFunctions.OvlK_IsComplete(OverlappedK) End Function ''' Initializes an overlappedK for re-use. The overlappedK is not return to its pool. Public Overridable Function ReUse(OverlappedK As KOVL_HANDLE) As Boolean Return AllKFunctions.OvlK_ReUse(OverlappedK) End Function ''' Returns an \c OverlappedK structure to it's pool. Public Overridable Function Release(OverlappedK As KOVL_HANDLE) As Boolean Return AllKFunctions.OvlK_Release(OverlappedK) End Function ''' Waits for overlapped I/O completion, and performs actions specified in \c WaitFlags. Public Overridable Function Wait(OverlappedK As KOVL_HANDLE, TimeoutMS As Integer, WaitFlags As KOVL_WAIT_FLAG, ByRef TransferredLength As Integer) As Boolean Return AllKFunctions.OvlK_Wait(OverlappedK, TimeoutMS, WaitFlags, TransferredLength) End Function ''' Waits for overlapped I/O completion, cancels on a timeout error and always releases the OvlK handle back to its pool. Public Overridable Function WaitAndRelease(OverlappedK As KOVL_HANDLE, TimeoutMS As Integer, ByRef TransferredLength As Integer) As Boolean Return AllKFunctions.OvlK_WaitAndRelease(OverlappedK, TimeoutMS, TransferredLength) End Function ''' Waits for overlapped I/O completion on the oldest acquired OverlappedK handle and performs actions specified in \c WaitFlags. Public Overridable Function WaitOldest(ByRef OverlappedK As KOVL_HANDLE, TimeoutMS As Integer, WaitFlags As KOVL_WAIT_FLAG, ByRef TransferredLength As Integer) As Boolean Return AllKFunctions.OvlK_WaitOldest(mHandleStruct, OverlappedK, TimeoutMS, WaitFlags, TransferredLength) End Function ''' Waits for overlapped I/O completion, cancels on a timeout error. Public Overridable Function WaitOrCancel(OverlappedK As KOVL_HANDLE, TimeoutMS As Integer, ByRef TransferredLength As Integer) As Boolean Return AllKFunctions.OvlK_WaitOrCancel(OverlappedK, TimeoutMS, TransferredLength) End Function #End Region End Class Public Class StmK Implements IDisposable Protected mHandleStruct As KSTM_HANDLE Protected mbDisposed As Boolean Protected Sub New() End Sub #Region "IDisposable Members" ''' Explicitly closes and frees the handle. Public Overridable Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub #End Region Protected Overrides Sub Finalize() Try Dispose(False) Finally MyBase.Finalize() End Try End Sub Protected Overridable Sub Dispose(disposing As Boolean) If Not mbDisposed Then If mHandleStruct.Pointer <> IntPtr.Zero Then AllKFunctions.StmK_Free(mHandleStruct) Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", [GetType]().Name, mHandleStruct.Pointer.ToInt64(), disposing) Else Debug.Print("{0} Dispose: [WARNING] Handle is null", [GetType]().Name) End If mHandleStruct = New KSTM_HANDLE(IntPtr.Zero) mbDisposed = True End If End Sub ''' Initializes a new uni-directional pipe stream. Protected Function Init(UsbHandle As KUSB_HANDLE, PipeID As Byte, MaxTransferSize As Integer, MaxPendingTransfers As Integer, MaxPendingIO As Integer, ByRef Callbacks As KSTM_CALLBACK, _ Flags As KSTM_FLAG) As Boolean Dim success As Boolean = AllKFunctions.StmK_Init(mHandleStruct, UsbHandle, PipeID, MaxTransferSize, MaxPendingTransfers, MaxPendingIO, _ Callbacks, Flags) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function #Region "Public Members" ''' Initializes a new uni-directional pipe stream. Public Sub New(UsbHandle As KUSB_HANDLE, PipeID As Byte, MaxTransferSize As Integer, MaxPendingTransfers As Integer, MaxPendingIO As Integer, ByRef Callbacks As KSTM_CALLBACK, _ Flags As KSTM_FLAG) Dim success As Boolean = AllKFunctions.StmK_Init(mHandleStruct, UsbHandle, PipeID, MaxTransferSize, MaxPendingTransfers, MaxPendingIO, _ Callbacks, Flags) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Calls the dispose method. Public Overridable Sub Free() Dispose() End Sub ''' Gets the handle class structure. Public ReadOnly Property Handle() As KSTM_HANDLE Get Return mHandleStruct End Get End Property ''' Reads data from the stream buffer. Public Overridable Function Read(Buffer As IntPtr, Offset As Integer, Length As Integer, ByRef TransferredLength As Integer) As Boolean Return AllKFunctions.StmK_Read(mHandleStruct, Buffer, Offset, Length, TransferredLength) End Function ''' Reads data from the stream buffer. Public Overridable Function Read(Buffer As Array, Offset As Integer, Length As Integer, ByRef TransferredLength As Integer) As Boolean Return AllKFunctions.StmK_Read(mHandleStruct, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), Offset, Length, TransferredLength) End Function ''' Starts the internal stream thread. Public Overridable Function Start() As Boolean Return AllKFunctions.StmK_Start(mHandleStruct) End Function ''' Stops the internal stream thread. Public Overridable Function [Stop](TimeoutCancelMS As Integer) As Boolean Return AllKFunctions.StmK_Stop(mHandleStruct, TimeoutCancelMS) End Function ''' Writes data to the stream buffer. Public Overridable Function Write(Buffer As IntPtr, Offset As Integer, Length As Integer, ByRef TransferredLength As Integer) As Boolean Return AllKFunctions.StmK_Write(mHandleStruct, Buffer, Offset, Length, TransferredLength) End Function ''' Writes data to the stream buffer. Public Overridable Function Write(Buffer As Array, Offset As Integer, Length As Integer, ByRef TransferredLength As Integer) As Boolean Return AllKFunctions.StmK_Write(mHandleStruct, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), Offset, Length, TransferredLength) End Function #End Region End Class Public Class IsoK Implements IDisposable Protected mHandleStruct As KISO_CONTEXT Protected mbDisposed As Boolean Protected Sub New() End Sub #Region "IDisposable Members" ''' Explicitly closes and frees the handle. Public Overridable Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub #End Region Protected Overrides Sub Finalize() Try Dispose(False) Finally MyBase.Finalize() End Try End Sub Protected Overridable Sub Dispose(disposing As Boolean) If Not mbDisposed Then If mHandleStruct.Pointer <> IntPtr.Zero Then AllKFunctions.IsoK_Free(mHandleStruct) Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", [GetType]().Name, mHandleStruct.Pointer.ToInt64(), disposing) Else Debug.Print("{0} Dispose: [WARNING] Handle is null", [GetType]().Name) End If mHandleStruct = New KISO_CONTEXT(IntPtr.Zero) mbDisposed = True End If End Sub ''' Creates a new isochronous transfer context. Protected Function Init(NumberOfPackets As Integer, StartFrame As Integer) As Boolean Dim success As Boolean = AllKFunctions.IsoK_Init(mHandleStruct, NumberOfPackets, StartFrame) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function #Region "Nested Structs" _ Private Structure KISO_CONTEXT_MAP ''' Additional ISO transfer flags. See \ref KISO_FLAG. Private ReadOnly Flags As KISO_FLAG ''' Specifies the frame number that the transfer should begin on (0 for ASAP). Private ReadOnly StartFrame As Integer ''' Contains the number of packets that completed with an error condition on return from the host controller driver. Private ReadOnly ErrorCount As Short ''' Specifies the number of packets that are described by the variable-length array member \c IsoPacket. Private ReadOnly NumberOfPackets As Short ''' Contains the URB Hdr.Status value on return from the host controller driver. Private ReadOnly UrbHdrStatus As Integer End Structure #End Region #Region "Public Members" ''' Creates a new isochronous transfer context. Public Sub New(NumberOfPackets As Integer, StartFrame As Integer) Dim success As Boolean = AllKFunctions.IsoK_Init(mHandleStruct, NumberOfPackets, StartFrame) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) End If Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Convenience function for enumerating ISO packets of an isochronous transfer context. Public Overridable Function EnumPackets(EnumPackets As KISO_ENUM_PACKETS_CB, StartPacketIndex As Integer, UserState As IntPtr) As Boolean Return AllKFunctions.IsoK_EnumPackets(mHandleStruct, EnumPackets, StartPacketIndex, UserState) End Function ''' Contains the number of packets that completed with an error condition on return from the host controller driver. Public Property ErrorCount() As Short Get Return Marshal.ReadInt16(mHandleStruct.Pointer, ofsErrorCount) End Get Set Marshal.WriteInt16(mHandleStruct.Pointer, ofsErrorCount, value) End Set End Property ''' Additional ISO transfer flags. See \ref KISO_FLAG. Public Property Flags() As KISO_FLAG Get Return CType(Marshal.ReadInt32(mHandleStruct.Pointer, ofsFlags), KISO_FLAG) End Get Set Marshal.WriteInt32(mHandleStruct.Pointer, ofsFlags, CInt(value)) End Set End Property ''' Calls the dispose method. Public Overridable Sub Free() Dispose() End Sub ''' Convenience function for getting all fields of a \ref KISO_PACKET. Public Overridable Function GetPacket(PacketIndex As Integer, ByRef IsoPacket As KISO_PACKET) As Boolean Return AllKFunctions.IsoK_GetPacket(mHandleStruct, PacketIndex, IsoPacket) End Function ''' Gets the handle class structure. Public ReadOnly Property Handle() As KISO_CONTEXT Get Return mHandleStruct End Get End Property ''' Specifies the number of packets that are described by the variable-length array member \c IsoPacket. Public Property NumberOfPackets() As Short Get Return Marshal.ReadInt16(mHandleStruct.Pointer, ofsNumberOfPackets) End Get Set Marshal.WriteInt16(mHandleStruct.Pointer, ofsNumberOfPackets, value) End Set End Property ''' Convenience function for re-using an isochronous transfer context in a subsequent request. Public Overridable Function ReUse() As Boolean Return AllKFunctions.IsoK_ReUse(mHandleStruct) End Function ''' Convenience function for setting all fields of a \ref KISO_PACKET. Public Overridable Function SetPacket(PacketIndex As Integer, ByRef IsoPacket As KISO_PACKET) As Boolean Return AllKFunctions.IsoK_SetPacket(mHandleStruct, PacketIndex, IsoPacket) End Function ''' Convenience function for setting the offset of all ISO packets of an isochronous transfer context. Public Overridable Function SetPackets(PacketSize As Integer) As Boolean Return AllKFunctions.IsoK_SetPackets(mHandleStruct, PacketSize) End Function ''' Specifies the frame number that the transfer should begin on (0 for ASAP). Public Property StartFrame() As Integer Get Return Marshal.ReadInt32(mHandleStruct.Pointer, ofsStartFrame) End Get Set Marshal.WriteInt32(mHandleStruct.Pointer, ofsStartFrame, value) End Set End Property ''' Contains the URB Hdr.Status value on return from the host controller driver. Public Property UrbHdrStatus() As Integer Get Return Marshal.ReadInt32(mHandleStruct.Pointer, ofsUrbHdrStatus) End Get Set Marshal.WriteInt32(mHandleStruct.Pointer, ofsUrbHdrStatus, value) End Set End Property #End Region #Region "Private Members" Private Shared ReadOnly ofsErrorCount As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "ErrorCount").ToInt32() Private Shared ReadOnly ofsFlags As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "Flags").ToInt32() Private Shared ReadOnly ofsNumberOfPackets As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "NumberOfPackets").ToInt32() Private Shared ReadOnly ofsStartFrame As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "StartFrame").ToInt32() Private Shared ReadOnly ofsUrbHdrStatus As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "UrbHdrStatus").ToInt32() #End Region End Class End Namespace