C# Class USBHIDTest.HIDDevice

Inheritance: IDisposable
显示文件 Open project: Wiladams/NewTOAPIA Class Usage Examples

Private Properties

Property Type Description
BeginAsyncRead void
GetDevicePath string
HIDDevice System
HidD_GetProductString bool
HidD_GetSerialNumberString bool
Initialise void

Public Methods

Method Description
CreateInputReport ( ) : InputReport

Virtual method to create an input report for this device. Override to use.

Dispose ( ) : void

Dispose method

FindDevice ( int nVid, int nPid, Type oType ) : HIDDevice

Finds a device given its PID and VID

RegisterForUsbEvents ( IntPtr hWnd, System.Guid gClass ) : IntPtr
ToString ( ) : string

Converts all significant properties of USBDevice to human readble string

UnregisterForUsbEvents ( IntPtr hHandle ) : bool

Unregisters notifications. Can be used in form dispose

Protected Methods

Method Description
Dispose ( bool bDisposing ) : void

Disposer called by both dispose and finalise

HandleDataReceived ( InputReport oInRep ) : void

virtual handler for any action to be taken when data is received. Override to use.

HandleDeviceRemoved ( ) : void

Virtual handler for any action to be taken when a device is removed. Override to use.

ReadCompleted ( IAsyncResult iResult ) : void

Callback for above. Care with this as it will be called on the background thread from the async read

Write ( OutputReport oOutRep ) : void

Write an output report to the device.

Private Methods

Method Description
BeginAsyncRead ( ) : void

Kicks off an asynchronous read which completes when data is read or when the device is disconnected. Uses a callback.

GetDevicePath ( IntPtr hInfoSet, SP_DEVICE_INTERFACE_DATA &oInterface ) : string

Helper method to return the device path given a DeviceInterfaceData structure and an InfoSet handle. Used in 'FindDevice' so check that method out to see how to get an InfoSet handle and a DeviceInterfaceData.

HIDDevice ( uint pid, uint vid ) : System
HidD_GetProductString ( IntPtr hDevice, IntPtr Buffer, uint BufferLength ) : bool
HidD_GetSerialNumberString ( IntPtr hDevice, IntPtr Buffer, uint BufferLength ) : bool
Initialise ( string strPath ) : void

Initialises the device

Method Details

CreateInputReport() public method

Virtual method to create an input report for this device. Override to use.
public CreateInputReport ( ) : InputReport
return InputReport

Dispose() public method

Dispose method
public Dispose ( ) : void
return void

Dispose() protected method

Disposer called by both dispose and finalise
protected Dispose ( bool bDisposing ) : void
bDisposing bool True if disposing
return void

FindDevice() public static method

Finds a device given its PID and VID
public static FindDevice ( int nVid, int nPid, Type oType ) : HIDDevice
nVid int Vendor id for device (VID)
nPid int Product id for device (PID)
oType System.Type Type of device class to create
return HIDDevice

HandleDataReceived() protected method

virtual handler for any action to be taken when data is received. Override to use.
protected HandleDataReceived ( InputReport oInRep ) : void
oInRep InputReport The input report that was received
return void

HandleDeviceRemoved() protected method

Virtual handler for any action to be taken when a device is removed. Override to use.
protected HandleDeviceRemoved ( ) : void
return void

ReadCompleted() protected method

Callback for above. Care with this as it will be called on the background thread from the async read
protected ReadCompleted ( IAsyncResult iResult ) : void
iResult IAsyncResult Async result parameter
return void

RegisterForUsbEvents() public static method

public static RegisterForUsbEvents ( IntPtr hWnd, System.Guid gClass ) : IntPtr
hWnd System.IntPtr
gClass System.Guid
return System.IntPtr

ToString() public method

Converts all significant properties of USBDevice to human readble string
public ToString ( ) : string
return string

UnregisterForUsbEvents() public static method

Unregisters notifications. Can be used in form dispose
public static UnregisterForUsbEvents ( IntPtr hHandle ) : bool
hHandle System.IntPtr Handle returned from RegisterForUSBEvents
return bool

Write() protected method

Write an output report to the device.
protected Write ( OutputReport oOutRep ) : void
oOutRep OutputReport Output report to write
return void