// Copyright © 2006-2010 Travis Robinson. All rights reserved.
//
// website: http://sourceforge.net/projects/libusbdotnet
// e-mail: libusbdotnet@gmail.com
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. or
// visit www.gnu.org.
//
//
using System;
using System.Collections.ObjectModel;
using LibUsbDotNet.Descriptors;
using LibUsbDotNet.Info;
using LibUsbDotNet.Main;
namespace LibUsbDotNet
{
///
/// The interface contains members needed communicate with an
/// interface of a usb device.
///
///
/// All USB device classes implement these members.
///
public interface IUsbInterface
{
///
/// A list of endpoints that have beened opened by this class.
///
UsbEndpointList ActiveEndpoints { get; }
///
/// Gets the available configurations for this
///
///
/// The first time this property is accessed it will query the for all configurations. Subsequent request will return a cached copy of all configurations.
///
ReadOnlyCollection Configs { get; }
///
/// Returns the DriverMode this USB device is using.
///
UsbDevice.DriverModeType DriverMode { get; }
///
/// Gets the actual device descriptor the the current .
///
UsbDeviceInfo Info { get; }
///
/// Gets a value indication if the device handle is valid.
///
bool IsOpen { get; }
///
/// Gets the class that opened the device, or null if the device was not opened by the class.
///
UsbRegistry UsbRegistryInfo { get; }
///
/// Closes and frees device resources. Once closed the device cannot be reopened. A new class must be obtained using the class.
///
/// True on success.
bool Close();
///
/// Sends/Receives an IO control message to endpoint 0.
///
/// Contains parameters for the control request. See section 9.3 USB Device Requests of the Universal Serial Bus Specification Revision 2.0 for more information.
/// Data to be sent/received from the device.
/// Length of the buffer param.
/// Number of bytes sent or received (depends on the direction of the control transfer).
/// True on success.
bool ControlTransfer(ref UsbSetupPacket setupPacket, IntPtr buffer, int bufferLength, out int lengthTransferred);
///
/// Transmits io control message to endpoint 0.
///
/// Contains parameters for the control request. See section 9.3 USB Device Requests of the Universal Serial Bus Specification Revision 2.0 for more information.
/// Data to be sent/received from the device. Th
/// Length of the buffer param.
/// Number of bytes sent or received (depends on the direction of the control transfer).
/// True on success.
bool ControlTransfer(ref UsbSetupPacket setupPacket, object buffer, int bufferLength, out int lengthTransferred);
///
/// Gets a specific descriptor from the device. See for more information.
///
/// The descriptor type ID to retrieve; this is usually one of the enumerations.
/// Descriptor index.
/// Descriptor language id.
/// Memory to store the returned descriptor in.
/// Length of the buffer parameter in bytes.
/// The number of bytes transferred to buffer upon success.
/// True on success.
bool GetDescriptor(byte descriptorType, byte index, short langId, IntPtr buffer, int bufferLength, out int transferLength);
///
/// Gets a specific descriptor from the device. See for more information.
///
/// The descriptor type ID to retrieve; this is usually one of the enumerations.
/// Descriptor index.
/// Descriptor language id.
/// Memory to store the returned descriptor in.
/// Length of the buffer parameter in bytes.
/// The number of bytes transferred to buffer upon success.
/// True on success.
bool GetDescriptor(byte descriptorType, byte index, short langId, object buffer, int bufferLength, out int transferLength);
///
/// Asking for the zero'th index is special - it returns a string
/// descriptor that contains all the language IDs supported by the
/// device. Typically there aren't many - often only one. The
/// language IDs are 16 bit numbers, and they start at the third byte
/// in the descriptor. See USB 2.0 specification, section 9.6.7, for
/// more information on this.
///
/// A collection of LCIDs that the current supports.
bool GetLangIDs(out short[] langIDs);
///
/// Gets a string descriptor from the device.
///
/// Buffer to store the returned string in upon success.
/// The language ID to retrieve the string in. (0x409 for english).
/// The string index to retrieve.
/// True on success.
bool GetString(out string stringData, short langId, byte stringIndex);
///
/// Opens/re-opens this USB device instance for communication.
///
///True if the device is already opened or was opened successfully. False if the device does not exists or is no longer valid.
bool Open();
///
/// Opens a endpoint for reading
///
/// Endpoint number for read operations.
/// Size of the read buffer allocated for the event.
/// A class ready for reading. If the specified endpoint is already been opened, the original class is returned.
UsbEndpointReader OpenEndpointReader(ReadEndpointID readEndpointID, int readBufferSize);
///
/// Opens an endpoint for reading
///
/// Endpoint number for read operations.
/// Size of the read buffer allocated for the event.
/// The type of endpoint to open.
/// A class ready for reading. If the specified endpoint is already been opened, the original class is returned.
UsbEndpointReader OpenEndpointReader(ReadEndpointID readEndpointID, int readBufferSize, EndpointType endpointType);
///
/// Opens a endpoint for reading
///
/// Endpoint number for read operations.
/// A class ready for reading. If the specified endpoint is already been opened, the original class is returned.
UsbEndpointReader OpenEndpointReader(ReadEndpointID readEndpointID);
///
/// Opens a endpoint for writing
///
/// Endpoint number for read operations.
/// A class ready for writing. If the specified endpoint is already been opened, the original class is returned.
UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID);
///
/// Opens an endpoint for writing
///
/// Endpoint number for read operations.
/// The type of endpoint to open.
/// A class ready for writing. If the specified endpoint is already been opened, the original class is returned.
UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID, EndpointType endpointType);
}
}