C# Class MonoLibUsb.MonoUsbApi

Libusb-1.0 low-level API library.
Mostrar archivo Open project: arvydas/BlinkStickDotNet Class Usage Examples

Public Methods

Method Description
BulkTransfer ( [ deviceHandle, byte endpoint, object data, int length, int &actualLength, int timeout ) : int

Perform a USB bulk transfer.

The direction of the transfer is inferred from the direction bits of the endpoint address.

For bulk reads, the length field indicates the maximum length of data you are expecting to receive. If less data arrives than expected, this function will return that data, so be sure to check the transferred output parameter.

You should also check the transferred parameter for bulk writes. Not all of the data may have been written. Also check transferred when dealing with a timeout error code. libusb may have to split your transfer into a number of chunks to satisfy underlying O/S requirements, meaning that the timeout may expire after the first few chunks have completed. libusb is careful not to lose any data that may have been transferred; do not assume that timeout conditions indicate a complete lack of I/O.

ControlTransfer ( [ deviceHandle, byte requestType, byte request, short value, short index, object data, short dataLength, int timeout ) : int

Perform a USB control transfer.

The direction of the transfer is inferred from the bmRequestType field of the setup packet.

The wValue, wIndex and wLength fields values should be given in host-endian byte order.

ControlTransferAsync ( [ deviceHandle, byte requestType, byte request, short value, short index, IntPtr pData, short dataLength, int timeout ) : int

Perform a USB control transfer for multi-threaded applications using the MonoUsbEventHandler class.

The direction of the transfer is inferred from the bmRequestType field of the setup packet.

The wValue, wIndex and wLength fields values should be given in host-endian byte order.

GetDescriptor ( MonoUsbDeviceHandle deviceHandle, byte descType, byte descIndex, IntPtr pData, int length ) : int

Retrieve a descriptor from the default control pipe.

This is a convenience function which formulates the appropriate control message to retrieve the descriptor.

GetDescriptor ( MonoUsbDeviceHandle deviceHandle, byte descType, byte descIndex, object data, int length ) : int

Retrieve a descriptor from the default control pipe.

This is a convenience function which formulates the appropriate control message to retrieve the descriptor.

GetDevice ( MonoUsbDeviceHandle devicehandle ) : MonoUsbProfileHandle

Get a MonoUsbProfileHandle for a MonoUsbDeviceHandle.

This function differs from the Libusb-1.0 C API in that when the new MonoUsbProfileHandle is returned, the device profile reference count is incremented ensuring the profile will remain valid as long as it is in-use.

GetPollfds ( MonoUsbSessionHandle sessionHandle ) : List

Retrieve a list of file descriptors that should be polled by your main loop as libusb event sources.

InterruptTransfer ( [ deviceHandle, byte endpoint, object data, int length, int &actualLength, int timeout ) : int

Perform a USB interrupt transfer.

The direction of the transfer is inferred from the direction bits of the endpoint address.

For interrupt reads, the length field indicates the maximum length of data you are expecting to receive. If less data arrives than expected, this function will return that data, so be sure to check the transferred output parameter.

You should also check the transferred parameter for interrupt writes. Not all of the data may have been written. Also check transferred when dealing with a timeout error code. libusb may have to split your transfer into a number of chunks to satisfy underlying O/S requirements, meaning that the timeout may expire after the first few chunks have completed. libusb is careful not to lose any data that may have been transferred; do not assume that timeout conditions indicate a complete lack of I/O.

MonoLibUsbErrorFromTransferStatus ( MonoUsbTansferStatus status ) : MonoUsbError

Converts a MonoUsbTansferStatus enum to a MonoUsbError enum.

OpenDeviceWithVidPid ( [ sessionHandle, short vendorID, short productID ) : MonoUsbDeviceHandle

Convenience function for finding a device with a particular idVendor/idProduct combination.

StrError ( MonoUsbError errcode ) : string

Get a string describing a MonoUsbError.

libusb_control_transfer ( MonoUsbDeviceHandle deviceHandle, libusb_control_setup &setupPacket, IntPtr pData, short dataLength, int timeout ) : int

Perform a USB control transfer.

The direction of the transfer is inferred from the bmRequestType field of the setup packet. The wValue, wIndex and wLength fields values should be given in host-endian byte order.

Private Methods

Method Description
AllocTransfer ( int isoPackets ) : IntPtr
AttachKernelDriver ( [ deviceHandle, int interfaceNumber ) : int
BulkTransfer ( [ deviceHandle, byte endpoint, IntPtr pData, int length, int &actualLength, int timeout ) : int
CancelTransfer ( IntPtr pTransfer ) : int
ClaimInterface ( [ deviceHandle, int interfaceNumber ) : int
ClearHalt ( [ deviceHandle, byte endpoint ) : int
Close ( IntPtr deviceHandle ) : void
ControlTransfer ( [ deviceHandle, byte requestType, byte request, short value, short index, IntPtr pData, short dataLength, int timeout ) : int
DefaultAsyncCB ( MonoUsbTransfer transfer ) : void
DetachKernelDriver ( [ deviceHandle, int interfaceNumber ) : int
ErrorCodeFromLibUsbError ( int ret, string &description ) : ErrorCode
EventHandlerActive ( [ sessionHandle ) : int
EventHandlingOk ( [ sessionHandle ) : int
Exit ( IntPtr pContext ) : void
FreeConfigDescriptor ( IntPtr pConfigDescriptor ) : void
FreeDeviceList ( IntPtr pHandleList, int unrefDevices ) : void
FreeTransfer ( IntPtr pTransfer ) : void
GetActiveConfigDescriptor ( [ deviceProfileHandle, [ configHandle ) : int
GetBusNumber ( [ deviceProfileHandle ) : byte
GetConfigDescriptor ( [ deviceProfileHandle, byte configIndex, [ configHandle ) : int
GetConfigDescriptorByValue ( [ deviceProfileHandle, byte bConfigurationValue, [ configHandle ) : int
GetConfiguration ( [ deviceHandle, int &configuration ) : int
GetDeviceAddress ( [ deviceProfileHandle ) : byte
GetDeviceDescriptor ( [ deviceProfileHandle, [ deviceDescriptor ) : int
GetDeviceInternal ( [ devicehandle ) : IntPtr
GetDeviceList ( [ sessionHandle, [ monoUSBProfileListHandle ) : int
GetMaxIsoPacketSize ( [ deviceProfileHandle, byte endpoint ) : int
GetMaxPacketSize ( [ deviceProfileHandle, byte endpoint ) : int
GetNextTimeout ( [ sessionHandle, UnixNativeTimeval &tv ) : int
GetPollfdsInternal ( [ sessionHandle ) : IntPtr
GetWindowsPriv ( MonoUsbProfileHandle profileHandle ) : internal_windows_device_priv
HandleEvents ( IntPtr pSessionHandle ) : int
HandleEvents ( [ sessionHandle ) : int
HandleEventsLocked ( [ sessionHandle, UnixNativeTimeval &tv ) : int
HandleEventsTimeout ( [ sessionHandle, UnixNativeTimeval &tv ) : int
Init ( IntPtr &pContext ) : int
InitAndStart ( ) : void

Calls MonoUsbEventHandler.Init() and MonoUsbEventHandler.Start if MonoUsbEventHandler.IsStopped = true.

InterruptTransfer ( [ deviceHandle, byte endpoint, IntPtr pData, int length, int &actualLength, int timeout ) : int
KernelDriverActive ( [ deviceHandle, int interfaceNumber ) : int
LockEventWaiters ( [ sessionHandle ) : void
LockEvents ( [ sessionHandle ) : void
Open ( [ deviceProfileHandle, IntPtr &deviceHandle ) : int
OpenDeviceWithVidPidInternal ( [ sessionHandle, short vendorID, short productID ) : IntPtr
PollfdsHandleTimeouts ( [ sessionHandle ) : int
RefDevice ( IntPtr pDeviceProfileHandle ) : IntPtr
ReleaseInterface ( [ deviceHandle, int interfaceNumber ) : int
ResetDevice ( [ deviceHandle ) : int
SetConfiguration ( [ deviceHandle, int configuration ) : int
SetDebug ( [ sessionHandle, int level ) : void
SetInterfaceAltSetting ( [ deviceHandle, int interfaceNumber, int alternateSetting ) : int
SetPollfdNotifiers ( [ sessionHandle, PollfdAddedDelegate addedDelegate, PollfdRemovedDelegate removedDelegate, IntPtr pUserData ) : void
StopAndExit ( ) : void

Calls MonoUsbEventHandler.Stop and MonoUsbEventHandler.Exit.

StrError ( int errcode ) : IntPtr
SubmitTransfer ( IntPtr pTransfer ) : int
TryLockEvents ( [ sessionHandle ) : int
UnlockEventWaiters ( [ sessionHandle ) : void
UnlockEvents ( [ sessionHandle ) : void
UnrefDevice ( IntPtr pDeviceProfileHandle ) : IntPtr
WaitForEvent ( [ sessionHandle, UnixNativeTimeval &timeval ) : int

Method Details

BulkTransfer() public static method

Perform a USB bulk transfer.

The direction of the transfer is inferred from the direction bits of the endpoint address.

For bulk reads, the length field indicates the maximum length of data you are expecting to receive. If less data arrives than expected, this function will return that data, so be sure to check the transferred output parameter.

You should also check the transferred parameter for bulk writes. Not all of the data may have been written. Also check transferred when dealing with a timeout error code. libusb may have to split your transfer into a number of chunks to satisfy underlying O/S requirements, meaning that the timeout may expire after the first few chunks have completed. libusb is careful not to lose any data that may have been transferred; do not assume that timeout conditions indicate a complete lack of I/O.

public static BulkTransfer ( [ deviceHandle, byte endpoint, object data, int length, int &actualLength, int timeout ) : int
deviceHandle [ A handle for the device to communicate with.
endpoint byte The address of a valid endpoint to communicate with.
data object /// A suitably-sized data buffer for either input or output (depending on endpoint). /// This value can be: /// /// An of bytes or other blittable types. /// An already allocated, pinned . In this case is used for the buffer address. /// An . /// ///
length int For bulk writes, the number of bytes from data to be sent. for bulk reads, the maximum number of bytes to receive into the data buffer.
actualLength int Output location for the number of bytes actually transferred.
timeout int Timeout (in milliseconds) that this function should wait before giving up due to no response being received. For an unlimited timeout, use value 0.
return int

ControlTransfer() public static method

Perform a USB control transfer.

The direction of the transfer is inferred from the bmRequestType field of the setup packet.

The wValue, wIndex and wLength fields values should be given in host-endian byte order.

public static ControlTransfer ( [ deviceHandle, byte requestType, byte request, short value, short index, object data, short dataLength, int timeout ) : int
deviceHandle [ A handle for the device to communicate with.
requestType byte The request type field for the setup packet.
request byte The request field for the setup packet.
value short The value field for the setup packet
index short The index field for the setup packet.
data object /// A suitably-sized data buffer for either input or output (depending on direction bits within bmRequestType). /// This value can be: /// /// An of bytes or other blittable types. /// An already allocated, pinned . In this case is used for the buffer address. /// An . /// ///
dataLength short The length field for the setup packet. The data buffer should be at least this size.
timeout int timeout (in milliseconds) that this function should wait before giving up due to no response being received. For an unlimited timeout, use value 0.
return int

ControlTransferAsync() public static method

Perform a USB control transfer for multi-threaded applications using the MonoUsbEventHandler class.

The direction of the transfer is inferred from the bmRequestType field of the setup packet.

The wValue, wIndex and wLength fields values should be given in host-endian byte order.

public static ControlTransferAsync ( [ deviceHandle, byte requestType, byte request, short value, short index, IntPtr pData, short dataLength, int timeout ) : int
deviceHandle [ A handle for the device to communicate with.
requestType byte The request type field for the setup packet.
request byte The request field for the setup packet.
value short The value field for the setup packet
index short The index field for the setup packet.
pData System.IntPtr A suitably-sized data buffer for either input or output (depending on direction bits within bmRequestType).
dataLength short The length field for the setup packet. The data buffer should be at least this size.
timeout int timeout (in milliseconds) that this function should wait before giving up due to no response being received. For an unlimited timeout, use value 0.
return int

GetDescriptor() public static method

Retrieve a descriptor from the default control pipe.

This is a convenience function which formulates the appropriate control message to retrieve the descriptor.

public static GetDescriptor ( MonoUsbDeviceHandle deviceHandle, byte descType, byte descIndex, IntPtr pData, int length ) : int
deviceHandle MonoUsbDeviceHandle Retrieve a descriptor from the default control pipe.
descType byte The descriptor type,
descIndex byte The index of the descriptor to retrieve.
pData System.IntPtr Output buffer for descriptor.
length int Size of data buffer.
return int

GetDescriptor() public static method

Retrieve a descriptor from the default control pipe.

This is a convenience function which formulates the appropriate control message to retrieve the descriptor.

public static GetDescriptor ( MonoUsbDeviceHandle deviceHandle, byte descType, byte descIndex, object data, int length ) : int
deviceHandle MonoUsbDeviceHandle Retrieve a descriptor from the default control pipe.
descType byte The descriptor type,
descIndex byte The index of the descriptor to retrieve.
data object Output buffer for descriptor. This object is pinned using .
length int Size of data buffer.
return int

GetDevice() public static method

Get a MonoUsbProfileHandle for a MonoUsbDeviceHandle.

This function differs from the Libusb-1.0 C API in that when the new MonoUsbProfileHandle is returned, the device profile reference count is incremented ensuring the profile will remain valid as long as it is in-use.

public static GetDevice ( MonoUsbDeviceHandle devicehandle ) : MonoUsbProfileHandle
devicehandle MonoUsbDeviceHandle A device handle.
return MonoLibUsb.Profile.MonoUsbProfileHandle

GetPollfds() public static method

Retrieve a list of file descriptors that should be polled by your main loop as libusb event sources.
public static GetPollfds ( MonoUsbSessionHandle sessionHandle ) : List
sessionHandle MonoUsbSessionHandle A valid .
return List

InterruptTransfer() public static method

Perform a USB interrupt transfer.

The direction of the transfer is inferred from the direction bits of the endpoint address.

For interrupt reads, the length field indicates the maximum length of data you are expecting to receive. If less data arrives than expected, this function will return that data, so be sure to check the transferred output parameter.

You should also check the transferred parameter for interrupt writes. Not all of the data may have been written. Also check transferred when dealing with a timeout error code. libusb may have to split your transfer into a number of chunks to satisfy underlying O/S requirements, meaning that the timeout may expire after the first few chunks have completed. libusb is careful not to lose any data that may have been transferred; do not assume that timeout conditions indicate a complete lack of I/O.

public static InterruptTransfer ( [ deviceHandle, byte endpoint, object data, int length, int &actualLength, int timeout ) : int
deviceHandle [ A handle for the device to communicate with.
endpoint byte The address of a valid endpoint to communicate with.
data object /// A suitably-sized data buffer for either input or output (depending on endpoint). /// This value can be: /// /// An of bytes or other blittable types. /// An already allocated, pinned . In this case is used for the buffer address. /// An . /// ///
length int For interrupt writes, the number of bytes from data to be sent. for interrupt reads, the maximum number of bytes to receive into the data buffer.
actualLength int Output location for the number of bytes actually transferred.
timeout int Timeout (in milliseconds) that this function should wait before giving up due to no response being received. For an unlimited timeout, use value 0.
return int

MonoLibUsbErrorFromTransferStatus() public static method

Converts a MonoUsbTansferStatus enum to a MonoUsbError enum.
public static MonoLibUsbErrorFromTransferStatus ( MonoUsbTansferStatus status ) : MonoUsbError
status MonoUsbTansferStatus the to convert.
return MonoUsbError

OpenDeviceWithVidPid() public static method

Convenience function for finding a device with a particular idVendor/idProduct combination.
public static OpenDeviceWithVidPid ( [ sessionHandle, short vendorID, short productID ) : MonoUsbDeviceHandle
sessionHandle [ A valid .
vendorID short The idVendor value to search for.
productID short The idProduct value to search for.
return MonoUsbDeviceHandle

StrError() public static method

Get a string describing a MonoUsbError.
public static StrError ( MonoUsbError errcode ) : string
errcode MonoUsbError The code to retrieve a description for.
return string

libusb_control_transfer() public static method

Perform a USB control transfer.
The direction of the transfer is inferred from the bmRequestType field of the setup packet. The wValue, wIndex and wLength fields values should be given in host-endian byte order.
public static libusb_control_transfer ( MonoUsbDeviceHandle deviceHandle, libusb_control_setup &setupPacket, IntPtr pData, short dataLength, int timeout ) : int
deviceHandle MonoUsbDeviceHandle A handle for the device to communicate with.
setupPacket libusb_control_setup The setup packet.
pData System.IntPtr A suitably-sized data buffer for either input or output (depending on direction bits within bmRequestType).
dataLength short The length field for the setup packet. The data buffer should be at least this size.
timeout int timeout (in millseconds) that this function should wait before giving up due to no response being received. For an unlimited timeout, use value 0.
return int