![]() |
Home | Libraries | Author | Links |
This class can be instantiated or be used as base class of a special libusb controlled USB device class which may reimplement the interface of stm::UsbDevice as well as that of the abstract base class stm::Device.
Definition at line 199 of file usbdevice.hpp.
Public Types | |
enum | DescribeFlags { DeviceReleaseNumber = DriverVersion << 1, DeviceBusNumber = DeviceReleaseNumber << 1, DeviceManufacturer = DeviceBusNumber << 1, DeviceProduct = DeviceManufacturer << 1, DeviceSerialNumber = DeviceProduct << 1, DeviceConfigurations = DeviceSerialNumber << 1, DeviceInterfaces = DeviceConfigurations << 1, DeviceAltSettings = DeviceInterfaces << 1, DeviceEndpoints = DeviceAltSettings << 1, DeviceChildren = DeviceEndpoints << 1 } |
Describe flags (bitwise orable). More... | |
Public Member Functions | |
UsbDevice (int defaultTimeout=Forever, const Descriptor &descr=Descriptor()) | |
Constructor of a UsbDevice object representing a libusb controlled USB device described by descr. | |
virtual | ~UsbDevice () |
Destructor. | |
virtual bool | canRead () const |
Return the read capability of this UsbDevice. | |
virtual bool | canWrite () const |
Return the write capability of this UsbDevice. | |
virtual bool | canControl () const |
Return the control capability of this UsbDevice. | |
virtual void | setError (int error, const std::string &msg=std::string()) const |
Set the error state and error string of this UsbDevice according to error and msg. | |
virtual void | setDescr (const Descriptor &descr) |
Set the Device::Descriptor of this UsbDevice to descr. | |
UsbPipe | pipe () const |
Return a copy of the UsbPipe object configured for this UsbDevice. | |
UsbPipe::Type | pipeType () const |
Return the type of the UsbPipe object configured for this UsbDevice as an enumerator of the enumeration UsbPipe::Type. | |
UsbPipe::Type | setPipe (UsbPipe pipe) |
Set the UsbPipe object configured for this UsbDevice to a copy of pipe and return its type. | |
virtual bool | isOpen () const |
Determine, if this UsbDevice is open. | |
virtual bool | open (unsigned int openMode) |
Open this UsbDevice in openMode. | |
virtual bool | close () |
Close this UsbDevice. | |
virtual int64_t | read (void *data, int64_t maxLen, int timeout=DefaultTimeout, unsigned int flags=NoFlags) |
Read maxLen bytes from the currently confiured USB pipe of this UsbDevice into the data buffer. | |
virtual int64_t | readPipe (UsbPipe pipe, void *data, int64_t maxLen, int timeout=DefaultTimeout, unsigned int flags=NoFlags) |
Atomically set the UsbPipe object configured for this UsbDevice to a copy of pipe and read maxLen bytes from that pipe into the data buffer. | |
virtual int64_t | write (const void *data, int64_t len, int timeout=DefaultTimeout, unsigned int flags=NoFlags) |
Write len bytes from the data buffer to the currently configured USB pipe of this UsbDevice. | |
virtual int64_t | writePipe (UsbPipe pipe, const void *data, int64_t len, int timeout=DefaultTimeout, unsigned int flags=NoFlags) |
Atomically set the UsbPipe object configured for this UsbDevice to a copy of pipe and write len bytes from the data buffer to that pipe. | |
virtual int64_t | control (unsigned int request, const void *ctrl, int64_t ctrlLen, void *data, int64_t dataLen, int timeout=DefaultTimeout, unsigned int flags=NoFlags) const |
Perform the control operation request over the default control pipe of this UsbDevice. | |
virtual std::ostream & | describe (std::ostream &os, unsigned int flags=DefaultProperties) const |
Insert a description of this UsbDevice into os. | |
bool | isA (const InterfaceClass &interfaceClass) const |
The method returns true, if this UsbDevice is a device supporting the libusb controlled USB device interface class described by interfaceClass. | |
template<class ForwardIterator> | |
bool | isA (ForwardIterator beginInterfaceClass, ForwardIterator endInterfaceClass) const |
The method template returns true, if this UsbDevice is a device supporting one of the the libusb controlled USB device interface classes whose description is contained in the half open interval [*beginInterfaceClass, *endInterfaceClass). | |
Static Public Member Functions | |
static size_t | enumerate (std::vector< Descriptor > &descriptors, const InterfaceClass &interfaceClass, bool append=false, bool quick=false) |
Enumerate all Device::Descriptor objects describing libusb controlled USB devices supporting the libusb controlled USB device interface class described by interfaceClass. | |
template<class ForwardIterator> | |
static size_t | enumerate (std::vector< Descriptor > &descriptors, ForwardIterator beginInterfaceClass, ForwardIterator endInterfaceClass, bool append=false) |
Enumerate all Device::Descriptor objects describing libusb controlled USB devices supporting one of the the libusb controlled USB device interface classes whose description is contained in the half open interval [*beginInterfaceClass, *endInterfaceClass). | |
static size_t | enumerateAll (std::vector< Descriptor > &descriptors) |
Enumerate all Device::Descriptor objects describing libusb controlled USB devices. | |
Classes | |
struct | InterfaceClass |
Type describing a libusb controlled USB device interface class. More... |
Describe flags (bitwise orable).
The enumerators of UsbDevice::DescribeFlags augment the Device::DescribeFlags further specifying the extent produced by describe().
Reimplemented from stm::Device.
Definition at line 208 of file usbdevice.hpp.
stm::UsbDevice::UsbDevice | ( | int | defaultTimeout = Forever , |
|
const Descriptor & | descr = Descriptor() | |||
) |
Constructor of a UsbDevice object representing a libusb controlled USB device described by descr.
[in] | defaultTimeout | Timeout in milliseconds used by default for all operations of this UsbDevice. |
[in] | descr | A valid Device::Descriptor for the libusb controlled USB device to be represented by the UsbDevice object to be constructed or an invalid Device::Descriptor. A valid Device::Descriptor is typically yielded by one of the static methods enumerate() or enumerateAll(). |
virtual stm::UsbDevice::~UsbDevice | ( | ) | [virtual] |
virtual bool stm::UsbDevice::canRead | ( | ) | const [virtual] |
Return the read capability of this UsbDevice.
true
. It is not necessary that this UsbDevice is open.
Reimplemented from stm::Device.
virtual bool stm::UsbDevice::canWrite | ( | ) | const [virtual] |
Return the write capability of this UsbDevice.
true
. It is not necessary that this UsbDevice is open.
Reimplemented from stm::Device.
virtual bool stm::UsbDevice::canControl | ( | ) | const [virtual] |
Return the control capability of this UsbDevice.
true
. It is not necessary that this UsbDevice is open.
Reimplemented from stm::Device.
virtual void stm::UsbDevice::setError | ( | int | error, | |
const std::string & | msg = std::string() | |||
) | const [virtual] |
Set the error state and error string of this UsbDevice according to error and msg.
[in] | error | Error state as one of the enumerators of Device::ErrorState optionally ored with one ore more of the enumerators of Device::ErrorFlags. |
[in] | msg | Error string. |
It is not necessary that this UsbDevice is open.
Reimplemented from stm::Device.
virtual void stm::UsbDevice::setDescr | ( | const Descriptor & | descr | ) | [virtual] |
Set the Device::Descriptor of this UsbDevice to descr.
[in] | descr | A valid Device::Descriptor of the libusb controlled USB device to be represented by this UsbDevice or an invalid Device::Descriptor. A valid descriptor is typically yielded by one of the static methods enumerate() or enumerateAll(). |
Implements stm::Device.
UsbPipe stm::UsbDevice::pipe | ( | ) | const |
Return a copy of the UsbPipe object configured for this UsbDevice.
a copy of the UsbPipe object configured for the libusb controlled USB device represented by this UsbDevice.
UsbPipe::Type stm::UsbDevice::pipeType | ( | ) | const |
Return the type of the UsbPipe object configured for this UsbDevice as an enumerator of the enumeration UsbPipe::Type.
UsbPipe::Bulk or UsbPipe::Interrupt, if this UsbDevice represents a libusb controlled USB device with a pipe configured for bulk or interrupt data transfer.
UsbPipe::Type stm::UsbDevice::setPipe | ( | UsbPipe | pipe | ) |
Set the UsbPipe object configured for this UsbDevice to a copy of pipe and return its type.
[in] | pipe | A UsbPipe object a copy of which is to be configured for the libusb controlled USB device represented by this UsbDevice. |
UsbPipe::Invalid
, in which case the UsbPipe object configured for this UsbDevice stays unchanged. virtual bool stm::UsbDevice::isOpen | ( | ) | const [virtual] |
Determine, if this UsbDevice is open.
true
, if this UsbDevice is open, that is if its open mode is not the Device::OpenMode enumerator Device::NoAccess.
false
, if this UsbDevice is not open, that is if its open mode is the Device::OpenMode enumerator Device::NoAccess.
Reimplemented from stm::Device.
virtual bool stm::UsbDevice::open | ( | unsigned int | openMode | ) | [virtual] |
Open this UsbDevice in openMode.
[in] | openMode | Open mode to be set. |
true
, if this UsbDevice could be opened in openMode.
false
, if this UsbDevice could not be opened in openMode. Then the error state of this UsbDevice is set to Device::OpenError.
Reimplemented from stm::Device.
virtual bool stm::UsbDevice::close | ( | ) | [virtual] |
Close this UsbDevice.
true
, if this UsbDevice could be closed successfully.
false
, if this UsbDevice could not be closed successfully. Then the error state of this UsbDevice is set to Device::CloseError.
Reimplemented from stm::Device.
virtual int64_t stm::UsbDevice::read | ( | void * | data, | |
int64_t | maxLen, | |||
int | timeout = DefaultTimeout , |
|||
unsigned int | flags = NoFlags | |||
) | [virtual] |
Read maxLen bytes from the currently confiured USB pipe of this UsbDevice into the data buffer.
[out] | data | Buffer for the data to be read. |
[in] | maxLen | Maximal number of bytes to be read. |
[in] | timeout | Operation timeout in milliseconds. If the value is Device::Forever, no timeout occurs. The default value Device::DefaultTimeout means, that the default timeout of this UsbDevice is used. |
[in] | flags | If the flag bit Device::AcceptTimeout is set, a timeout is no error. |
-1
, if the read operation was not successful. Then the error state of this UsbDevice is set to Device::ReadError.
Reimplemented from stm::Device.
virtual int64_t stm::UsbDevice::readPipe | ( | UsbPipe | pipe, | |
void * | data, | |||
int64_t | maxLen, | |||
int | timeout = DefaultTimeout , |
|||
unsigned int | flags = NoFlags | |||
) | [virtual] |
Atomically set the UsbPipe object configured for this UsbDevice to a copy of pipe and read maxLen bytes from that pipe into the data buffer.
[in] | pipe | A UsbPipe object a copy of which is to be configured for the libusb controlled USB device represented by this UsbDevice. |
[out] | data | Buffer for the data to be read. |
[in] | maxLen | Maximal number of bytes to be read. |
[in] | timeout | Operation timeout in milliseconds. If the value is Device::Forever, no timeout occurs. The default value Device::DefaultTimeout means, that the default timeout of this UsbDevice is used. |
[in] | flags | If the flag bit Device::AcceptTimeout is set, a timeout is no error. |
-1
, if the read operation was not successful. Then the error state of this UsbDevice is set to Device::ReadError.
virtual int64_t stm::UsbDevice::write | ( | const void * | data, | |
int64_t | len, | |||
int | timeout = DefaultTimeout , |
|||
unsigned int | flags = NoFlags | |||
) | [virtual] |
Write len bytes from the data buffer to the currently configured USB pipe of this UsbDevice.
[in] | data | Buffer containing the data to be written. |
[in] | len | Number of bytes to be written. |
[in] | timeout | Operation timeout in milliseconds. If the value is Device::Forever, no timeout occurs. The default value Device::DefaultTimeout means, that the default timeout of this UsbDevice is used. |
[in] | flags | If the flag bit Device::AcceptTimeout is set, a timeout is no error. |
-1
, if the write operation was not successful. Then the error state of this UsbDevice is set to Device::WriteError.
Reimplemented from stm::Device.
virtual int64_t stm::UsbDevice::writePipe | ( | UsbPipe | pipe, | |
const void * | data, | |||
int64_t | len, | |||
int | timeout = DefaultTimeout , |
|||
unsigned int | flags = NoFlags | |||
) | [virtual] |
Atomically set the UsbPipe object configured for this UsbDevice to a copy of pipe and write len bytes from the data buffer to that pipe.
[in] | pipe | A UsbPipe object a copy of which is to be configured for the libusb controlled USB device represented by this UsbDevice. |
[in] | data | Buffer containing the data to be written. |
[in] | len | Number of bytes to be written. |
[in] | timeout | Operation timeout in milliseconds. If the value is Device::Forever, no timeout occurs. The default value Device::DefaultTimeout means, that the default timeout of this UsbDevice is used. |
[in] | flags | If the flag bit Device::AcceptTimeout is set, a timeout is no error. |
-1
, if the write operation was not successful. Then the error state of this UsbDevice is set to Device::WriteError.
virtual int64_t stm::UsbDevice::control | ( | unsigned int | request, | |
const void * | ctrl, | |||
int64_t | ctrlLen, | |||
void * | data, | |||
int64_t | dataLen, | |||
int | timeout = DefaultTimeout , |
|||
unsigned int | flags = NoFlags | |||
) | const [virtual] |
Perform the control operation request over the default control pipe of this UsbDevice.
[in] | request | Specifies the particular control operation to be performed. |
[in] | ctrl | Pointer to a UsbCtrl object specifying the request type (in which the transfer direction is encoded), the value and the index of the request. |
[in] | ctrlLen | sizeof(UsbCtrl). |
[in,out] | data | Buffer for the input or output data. |
[in] | dataLen | Byte length of the data buffer. |
[in] | timeout | Operation timeout in milliseconds. If the value is Device::Forever, no timeout occurs. The default value Device::DefaultTimeout means, that the default timeout of this UsbDevice is used. |
[in] | flags | If the flag bit Device::AcceptTimeout is set, a timeout is no error. |
-1
, if the operation was not successful. Then the error state of this UsbDevice is set to the Device::ErrorState enumerator Device::ControlError.
Reimplemented from stm::Device.
virtual std::ostream& stm::UsbDevice::describe | ( | std::ostream & | os, | |
unsigned int | flags = DefaultProperties | |||
) | const [virtual] |
Insert a description of this UsbDevice into os.
[in] | os | The output stream to insert the description. |
[in] | flags | Description flags. |
Reimplemented from stm::Device.
bool stm::UsbDevice::isA | ( | const InterfaceClass & | interfaceClass | ) | const |
The method returns true, if this UsbDevice is a device supporting the libusb controlled USB device interface class described by interfaceClass.
That means it returns true, if the Device::Descriptor of this UsbDevice describes a libusb controlled USB device supporting the libusb controlled USB device interface class described by interfaceClass, else false.
bool stm::UsbDevice::isA | ( | ForwardIterator | beginInterfaceClass, | |
ForwardIterator | endInterfaceClass | |||
) | const |
The method template returns true, if this UsbDevice is a device supporting one of the the libusb controlled USB device interface classes whose description is contained in the half open interval [*beginInterfaceClass, *endInterfaceClass).
That means it returns true, if the Device::Descriptor of this UsbDevice describes a libusb controlled USB device supporting one of the libusb controlled USB device interface classes described by that interval, else false.
static size_t stm::UsbDevice::enumerate | ( | std::vector< Descriptor > & | descriptors, | |
const InterfaceClass & | interfaceClass, | |||
bool | append = false , |
|||
bool | quick = false | |||
) | [static] |
Enumerate all Device::Descriptor objects describing libusb controlled USB devices supporting the libusb controlled USB device interface class described by interfaceClass.
The static method clears the vector descriptors, scans the system for all libusb controlled USB devices supporting the libusb controlled USB device interface class described by interfaceClass, stores the Device::Descriptor objects describing those devices in the vector descriptors and returns the size of that vector. If quick is true, the system is not scanned for new hardware.
static size_t stm::UsbDevice::enumerate | ( | std::vector< Descriptor > & | descriptors, | |
ForwardIterator | beginInterfaceClass, | |||
ForwardIterator | endInterfaceClass, | |||
bool | append = false | |||
) | [static] |
Enumerate all Device::Descriptor objects describing libusb controlled USB devices supporting one of the the libusb controlled USB device interface classes whose description is contained in the half open interval [*beginInterfaceClass, *endInterfaceClass).
The static method template clears the vector descriptors, scans the system for all libusb controlled USB devices supporting one of the libusb controlled USB device interface classes described by that interval, stores the Device::Descriptor objects describing those devices in the vector descriptors and returns the size of that vector.
static size_t stm::UsbDevice::enumerateAll | ( | std::vector< Descriptor > & | descriptors | ) | [static] |
Enumerate all Device::Descriptor objects describing libusb controlled USB devices.
The static method template clears the vector descriptors, scans the system for all libusb controlled USB devices, stores the Device::Descriptor objects describing those devices in the vector descriptors and returns the size of that vector.
© Copyright Tom Michaelis 2002-2007
Distributed under the SysToMath Software License (See the accompanying file license.txt or a copy at www.SysToMath.com).