QUsbTransfer Class

This class handles transfers between endpoints and the host. More...

Header: #include <QUsbTransfer>
qmake: QT += usb
Inherits: QIODevice

Note: All functions in this class are reentrant.

Public Types

enum Status { transferCompleted, transferError, transferTimeout, transferCanceled, ..., transferOverflow }
enum Type { controlTransfer, isochronousTransfer, bulkTransfer, interruptTransfer, streamTransfer }
enum bRequest { requestGetStatus, requestClearFeature, requestSetFeature, requestSetAddress, ..., requestIsochDelay }
enum bmRequestType { requestStandard, requestClass, requestVendor, requestReserved, ..., recipientOther }

Properties

  • 1 property inherited from QObject

Public Functions

QUsbTransfer(QUsbDevice *dev, Type type, QUsbDevice::Endpoint in, QUsbDevice::Endpoint out)
~QUsbTransfer()
QUsbDevice::Endpoint endpointIn() const
QUsbDevice::Endpoint endpointOut() const
void makeControlPacket(char *buffer, QUsbTransfer::bmRequestType bmRequestType, QUsbTransfer::bRequest bRequest, quint16 wValue, quint16 wIndex, quint16 wLength) const
bool poll()
bool polling()
void setPolling(bool enable)
Status status() const
Type type() const

Reimplemented Public Functions

virtual qint64 bytesAvailable() const
virtual qint64 bytesToWrite() const
virtual void close()
virtual bool isSequential() const
virtual bool open(QIODevice::OpenMode mode)
virtual bool waitForBytesWritten(int msecs)
virtual bool waitForReadyRead(int msecs)
  • 44 public functions inherited from QIODevice
  • 32 public functions inherited from QObject

Public Slots

  • 1 public slot inherited from QObject

Signals

void error(Status error)

Reimplemented Protected Functions

virtual qint64 readData(char *data, qint64 maxSize)
virtual qint64 writeData(const char *data, qint64 maxSize)
  • 5 protected functions inherited from QIODevice
  • 9 protected functions inherited from QObject

Additional Inherited Members

  • 1 public variable inherited from QObject
  • 10 static public members inherited from QObject
  • 5 protected functions inherited from QIODevice
  • 9 protected functions inherited from QObject
  • 2 protected variables inherited from QObject

Detailed Description

This class handles transfers between endpoints and the host.

It works on top of libusb's async module. The QUsbDevice is set as parent object.

Member Type Documentation

enum QUsbTransfer::Status

This enum describres the last transfer status.

ConstantValueDescription
QUsbTransfer::transferCompleted0Transfer completed without errors. At least one byte transfered.
QUsbTransfer::transferError1Transfer completed with unknown error.
QUsbTransfer::transferTimeout2Transfer timed out.
QUsbTransfer::transferCanceled3Transfer canceled.
QUsbTransfer::transferStall4Transfer stalled (most likely hardware issue).
QUsbTransfer::transferNoDevice5Device not found.
QUsbTransfer::transferOverflow6More data received than requested.

enum QUsbTransfer::Type

This enum describres the type of transfer this object handles.

ConstantValue
QUsbTransfer::controlTransfer0
QUsbTransfer::isochronousTransfer1
QUsbTransfer::bulkTransfer2
QUsbTransfer::interruptTransfer3
QUsbTransfer::streamTransfer4

enum QUsbTransfer::bRequest

This enum describres a bRequest packet.

ConstantValue
QUsbTransfer::requestGetStatus0x00
QUsbTransfer::requestClearFeature0x01
QUsbTransfer::requestSetFeature0x03
QUsbTransfer::requestSetAddress0x05
QUsbTransfer::requestGetDescriptor0x06
QUsbTransfer::requestSetDescriptor0x07
QUsbTransfer::requestGetConfiguration0x08
QUsbTransfer::requestSetConfiguration0x09
QUsbTransfer::requestGetInterface0x0A
QUsbTransfer::requestSetInterface0x0B
QUsbTransfer::requestSynchFrame0x0C
QUsbTransfer::requestSetSel0x30
QUsbTransfer::requestIsochDelay0x31

enum QUsbTransfer::bmRequestType

This enum describres a bmRequestType packet.

ConstantValue
QUsbTransfer::requestStandard( 0x00<5 )
QUsbTransfer::requestClass( 0x01<5 )
QUsbTransfer::requestVendor( 0x02<5 )
QUsbTransfer::requestReserved( 0x03<5 )
QUsbTransfer::recipientDevice0x00
QUsbTransfer::recipientInterface0x01
QUsbTransfer::recipientEndpoint0x02
QUsbTransfer::recipientOther0x03

Property Documentation

endpointIn : const QUsbDevice::Endpoint

IN endpoint.

Access functions:

QUsbDevice::Endpoint endpointIn() const

endpointOut : const QUsbDevice::Endpoint

OUT endpoint.

Access functions:

QUsbDevice::Endpoint endpointOut() const

polling : bool

polling status.

Access functions:

bool polling()
void setPolling(bool enable)

type : const Type

Transfer type.

Access functions:

Type type() const

Member Function Documentation

QUsbTransfer::QUsbTransfer(QUsbDevice *dev, Type type, QUsbDevice::Endpoint in, QUsbDevice::Endpoint out)

QUsbTransfer constructor.

This create an object of the given transfer type, using endpoints in and out.

dev will be set as parent object.

QUsbTransfer::~QUsbTransfer()

Will cancel all transfers on exit.

[virtual] qint64 QUsbTransfer::bytesAvailable() const

Reimplemented from QIODevice::bytesAvailable().

Bytes available to read.

[virtual] qint64 QUsbTransfer::bytesToWrite() const

Reimplemented from QIODevice::bytesToWrite().

Bytes left to write.

[slot] void QUsbTransfer::cancelTransfer()

[virtual] void QUsbTransfer::close()

Reimplemented from QIODevice::close().

Close the transfer.

This will cancel any ongoing transfers.

QUsbDevice::Endpoint QUsbTransfer::endpointIn() const

Returns the transfer IN endpoint.

Note: Getter function for property endpointIn.

QUsbDevice::Endpoint QUsbTransfer::endpointOut() const

Returns the transfer OUT endpoint.

Note: Getter function for property endpointOut.

[signal] void QUsbTransfer::error(Status error)

emits a signal on any transfer error.

[virtual] bool QUsbTransfer::isSequential() const

Reimplemented from QIODevice::isSequential().

Always returns true.

void QUsbTransfer::makeControlPacket(char *buffer, QUsbTransfer::bmRequestType bmRequestType, QUsbTransfer::bRequest bRequest, quint16 wValue, quint16 wIndex, quint16 wLength) const

Create a control packet using buffer, bmRequestType, bRequest, wValue, bRequest, wIndex, wLength.

[virtual] bool QUsbTransfer::open(QIODevice::OpenMode mode)

Reimplemented from QIODevice::open().

Open the transfer with mode.

Returns true on success.

bool QUsbTransfer::poll()

Manual IN (read) polling.

return true if successful.

bool QUsbTransfer::polling()

Get polling status.

return true if enabled.

Note: Getter function for property polling.

See also setPolling().

[virtual protected] qint64 QUsbTransfer::readData(char *data, qint64 maxSize)

Reimplemented from QIODevice::readData().

/reimp

Read maxSize bytes from the internal buffer to data.

Returns read bytes.

void QUsbTransfer::setPolling(bool enable)

enable or disable automating polling.

Note: Setter function for property polling.

See also polling().

Status QUsbTransfer::status() const

Get the transfer status.

Type QUsbTransfer::type() const

Returns the transfer type.

Note: Getter function for property type.

[virtual] bool QUsbTransfer::waitForBytesWritten(int msecs)

Reimplemented from QIODevice::waitForBytesWritten().

Wait for at least one byte to be written for msecs milliseconds.

Returns true if any data was written before timeout.

[virtual] bool QUsbTransfer::waitForReadyRead(int msecs)

Reimplemented from QIODevice::waitForReadyRead().

Wait for at least one byte to be available for msecs milliseconds.

Returns true if any data was read before timeout.

[virtual protected] qint64 QUsbTransfer::writeData(const char *data, qint64 maxSize)

Reimplemented from QIODevice::writeData().

Copies maxSize bytes from data to the internal write buffer and schedules an OUT transfer.

Returns bytes written to the buffer.