Click or drag to resize

UsbDevice Class

Represents a matching USB device that has been attached to the host computer.
Inheritance Hierarchy
SystemObject
  WinUsbNetUsbDevice

Namespace:  WinUsbNet
Assembly:  WinUsbNet (in WinUsbNet.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public sealed class UsbDevice

The UsbDevice type exposes the following members.

Properties
  NameDescription
Public propertyDefaultReadTimeout
Gets or sets the initial ReadTimeout value.
Public propertyDeviceName
Gets the string generated by Windows that uniquely identifies the USB device.
Public propertyCode exampleGetMyString
Callback function used to get the string returned by ToString.
Public propertyIsAttached
Gets a value indicating if this UsbDevice is valid.
Public propertyIsOpen
Gets a value indicating if the UsbDevice is open or closed.
Public propertyPipeStreams
Gets the collection of PipeStream objects corresponding to the USB communication pipes of a USB device.
Public propertyTag
Gets or sets the object that contains data about the UsbDevice.
Top
Methods
  NameDescription
Public methodClose
Closes the USB device.
Public methodControlRead
Initiates a USB control transfer that reads data from the USB device.
Public methodControlWrite
Initiates a USB control transfer with optional data sent to the USB device.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Destructor.
(Overrides ObjectFinalize.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodOpen
Open the USB device for I/O.
Public methodToString
Returns a string that represents the UsbDevice.
(Overrides ObjectToString.)
Top
Remarks

UsbDevice represents a USB device that has been attached and whose WinUSB GUID matches the GUID of the parent WinUsbManager. You do not create a UsbDevice directly. A UsbDevice is automatically placed in the UsbDevices collection for each matching USB device that is attached.

A UsbDevice is valid only as long as the corresponding USB device remains attached to the host. Once it is been detached, the UsbDevice is closed if it was open, the IsAttached property is set to false, and calls to the Open method will throw an exception. Reattaching the USB device will not make the existing UsbDevice valid again. Instead a new UsbDevice is created and added to the UsbDevices collection of the parent WinUsbManager.

To communicate with the USB device, you must first call the Open method. This will populate the PipeStreams collection with PipeStream objects corresponding to the endpoints of the USB device. When you are finished communicating with the USB device, call the Close method, which will set the PipeStreams property to null.

You may open, transfer data, and close the UsbDevice any number of times. This can allow you to share the USB device with multiple applications.

When the UsbDevice is open, you can send and receive USB control transfers using the ControlWrite and ControlRead methods. To transfer data with other endpoints, use the endpoint number as an index into the PipeStreams collection, then use the returned PipeStream to transfer data.

The index of a UsbDevice in the UsbDevices collection of the parent WinUsbManager can change as USB devices are attached and detached. UsbDevice includes a Tag property that can be assigned any generic object to make it easier to track each UsbDevice.

See Also