An IoInterface for dealing specifically with Xsens USB devices. More...
#include <usbinterface.h>
Public Member Functions | |
XsResultValue | close (void) |
Close the USB communication port. More... | |
XsResultValue | closeUsb (void) |
Close the USB communication port. More... | |
XsResultValue | flushData (void) |
Flush all data in the buffers to and from the device. More... | |
XsResultValue | getLastResult (void) const |
Return the error code of the last operation. More... | |
void | getPortName (XsString &portname) const |
Retrieve the port name that was last successfully opened. More... | |
bool | getRawIo (void) |
Retrieves the state of the RAWIO mode of the USB interface. More... | |
uint32_t | getTimeout (void) const |
Return the current timeout value. More... | |
bool | isOpen (void) const |
Return whether the USB communication port is open or not. More... | |
XsResultValue | open (const XsPortInfo &portInfo, XsFilePos readBufSize=0, XsFilePos writeBufSize=0, PortOptions=PO_XsensDefaults) override |
Open a communication channel to the given USB port name. More... | |
XsResultValue | readData (XsFilePos maxLength, void *data, XsFilePos *length=NULL) |
Read data from the serial port and put it into the data buffer. More... | |
XsResultValue | readData (XsFilePos maxLength, XsByteArray &data) override |
Read data from the USB port and put it into the data buffer. More... | |
void | setRawIo (bool enable) |
Sets the RAWIO mode of the USB interface. More... | |
XsResultValue | setTimeout (uint32_t ms) |
Set the default timeout value to use in blocking operations. More... | |
uint8_t | usbAddress () const |
The address of the device (libusb/linux only) More... | |
uint8_t | usbBus () const |
The USB bus number this device is on (libusb/linux only) More... | |
UsbInterface () | |
Default constructor, initializes all members to their default values. More... | |
XsResultValue | waitForData (XsFilePos maxLength, void *data, XsFilePos *length=NULL) |
Wait for data to arrive or a timeout to occur. More... | |
virtual XsResultValue | waitForData (XsFilePos maxLength, XsByteArray &data) |
Wait for data to arrive or a timeout to occur. More... | |
XsResultValue | writeData (const XsByteArray &data, XsFilePos *written=NULL) override |
Write the data to the USB port. More... | |
XsResultValue | writeData (XsFilePos length, const void *data, XsFilePos *written=NULL) |
Write the data to the USB port. More... | |
XSENS_DISABLE_COPY (UsbInterface) | |
~UsbInterface () | |
Destructor, de-initializes, frees memory allocated for buffers, etc. More... | |
![]() | |
XSENS_DISABLE_COPY (StreamInterface) | |
~StreamInterface () | |
Destroy the stream interface. More... | |
![]() | |
virtual XsResultValue | appendData (const XsByteArray &bdata) |
Write data to the end of the file. More... | |
virtual void | cancelIo (void) const |
Cancel any pending io requests. More... | |
virtual XsResultValue | closeAndDelete (void) |
Close the file and delete it. More... | |
virtual XsResultValue | create (const XsString &filename) |
Create an empty file. More... | |
virtual XsResultValue | deleteData (XsFilePos start, XsFilePos length) |
Delete the given data from the file. More... | |
virtual XsResultValue | find (const XsByteArray &needleV, XsFilePos &pos) |
Find a string of bytes in the file. More... | |
virtual XsFilePos | getFileSize (void) const |
Return the size of the file. More... | |
virtual XsResultValue | getName (XsString &filename) const |
Retrieve the filename that was last successfully opened. More... | |
virtual XsFilePos | getReadPosition (void) const |
Return the current read position. More... | |
virtual XsFilePos | getWritePosition (void) const |
Return the current write position. More... | |
virtual XsResultValue | insertData (XsFilePos start, const XsByteArray &data) |
Insert the given data into the file. More... | |
virtual bool | isReadOnly (void) const |
Return whether the file is read-only or not. More... | |
virtual XsResultValue | open (const XsString &filename, bool createNew, bool readOnly) |
Open a file. More... | |
virtual XsResultValue | setReadPosition (XsFilePos pos) |
Set the new absolute read position. More... | |
virtual XsResultValue | setWritePosition (XsFilePos pos=-1) |
Set the new absolute write position. More... | |
virtual XsResultValue | waitForData (XsFilePos maxLength, XsByteArray &data) |
Wait for data to arrive or a timeout to occur. More... | |
virtual | ~IoInterface () |
Destructor. More... | |
Private Attributes | |
UsbInterfacePrivate * | d |
Additional Inherited Members | |
![]() | |
enum | PortOptions { PO_NoFlowControl = 0, PO_RtsCtsFlowControl = (1 << 0), PO_DtrDsrFlowControl = (1 << 1), PO_XonXoffFlowControl = (1 << 2), PO_OneStopBit = 0, PO_TwoStopBits = (1 << 3), PO_XsensDefaults = (PO_NoFlowControl | PO_TwoStopBits) } |
Options for flow control and stopbits which must be used when opening a port. More... | |
![]() | |
StreamInterface () | |
Create a stream interface. More... | |
![]() | |
IoInterface () | |
Constructor. More... | |
XSENS_DISABLE_COPY (IoInterface) | |
An IoInterface for dealing specifically with Xsens USB devices.
Definition at line 89 of file usbinterface.h.
UsbInterface::UsbInterface | ( | ) |
Default constructor, initializes all members to their default values.
Definition at line 400 of file usbinterface.cpp.
UsbInterface::~UsbInterface | ( | ) |
Destructor, de-initializes, frees memory allocated for buffers, etc.
Definition at line 429 of file usbinterface.cpp.
|
virtual |
Close the USB communication port.
Implements IoInterface.
Definition at line 449 of file usbinterface.cpp.
XsResultValue UsbInterface::closeUsb | ( | void | ) |
Close the USB communication port.
Definition at line 460 of file usbinterface.cpp.
|
virtual |
Flush all data in the buffers to and from the device.
Implements IoInterface.
Definition at line 529 of file usbinterface.cpp.
|
virtual |
Return the error code of the last operation.
Implements IoInterface.
Definition at line 566 of file usbinterface.cpp.
void UsbInterface::getPortName | ( | XsString & | portname | ) | const |
Retrieve the port name that was last successfully opened.
Definition at line 1112 of file usbinterface.cpp.
bool UsbInterface::getRawIo | ( | void | ) |
Retrieves the state of the RAWIO mode of the USB interface.
Definition at line 955 of file usbinterface.cpp.
|
virtual |
Return the current timeout value.
Implements StreamInterface.
Definition at line 572 of file usbinterface.cpp.
|
virtual |
Return whether the USB communication port is open or not.
Implements IoInterface.
Definition at line 578 of file usbinterface.cpp.
|
overridevirtual |
Open a communication channel to the given USB port name.
Reimplemented from IoInterface.
Definition at line 584 of file usbinterface.cpp.
XsResultValue UsbInterface::readData | ( | XsFilePos | maxLength, |
void * | data, | ||
XsFilePos * | length = NULL |
||
) |
Read data from the serial port and put it into the data buffer.
This function reads up to maxLength bytes from the USB port (non-blocking) and puts it into the data buffer.
maxLength | The maximum number of bytes to read. |
data | Pointer to a buffer that will store the received data. |
length | The number of bytes placed into data . |
Definition at line 842 of file usbinterface.cpp.
|
overridevirtual |
Read data from the USB port and put it into the data buffer.
This function reads up to maxLength bytes from the port (non-blocking) and puts it into the data buffer.
maxLength | The maximum amount of data read. |
data | The buffer that will store the received data. |
Implements IoInterface.
Definition at line 824 of file usbinterface.cpp.
void UsbInterface::setRawIo | ( | bool | enable | ) |
Sets the RAWIO mode of the USB interface.
enable | : If true will enable RAW IO mode |
Definition at line 937 of file usbinterface.cpp.
|
virtual |
Set the default timeout value to use in blocking operations.
This function sets the value of m_timeout. There is no infinity value. The value 0 means that the default value is used.
ms | The desired timeout in milliseconds |
Implements StreamInterface.
Definition at line 912 of file usbinterface.cpp.
uint8_t UsbInterface::usbAddress | ( | ) | const |
The address of the device (libusb/linux only)
Definition at line 1098 of file usbinterface.cpp.
uint8_t UsbInterface::usbBus | ( | ) | const |
The USB bus number this device is on (libusb/linux only)
Definition at line 1084 of file usbinterface.cpp.
XsResultValue UsbInterface::waitForData | ( | XsFilePos | maxLength, |
void * | data, | ||
XsFilePos * | length = NULL |
||
) |
Wait for data to arrive or a timeout to occur.
The function waits until maxLength
data is available or until a timeout occurs. The function returns success if data is available or XsResultValue::TIMEOUT if a timeout occurred. A timeout value of 0 indicates that the default timeout stored in the class should be used.
maxLength | The maximum number of bytes to wait for |
data | A buffer that will be filled with the read data. It must be able to contain at least maxLength bytes. |
length | An optional pointer to storage for the actual number of bytes read. |
Definition at line 978 of file usbinterface.cpp.
XsResultValue IoInterface::waitForData |
Wait for data to arrive or a timeout to occur.
The function waits until maxLength
data is available or until a timeout occurs. The function returns success if data is available or XsResultValue::TIMEOUT if a timeout occurred. A timeout value of 0 indicates that the default timeout stored in the class should be used.
maxLength | The maximum number of bytes to read before returning |
data | The buffer to put the read data in. |
Definition at line 107 of file iointerface.cpp.
|
overridevirtual |
Write the data to the USB port.
The function writes the given data to the connected USB port. The default timeout is respected in this operation.
data | The data to be written |
written | An optional pointer to storage for the actual number of bytes that were written |
Implements IoInterface.
Definition at line 1014 of file usbinterface.cpp.
XsResultValue UsbInterface::writeData | ( | XsFilePos | length, |
const void * | data, | ||
XsFilePos * | written = NULL |
||
) |
Write the data to the USB port.
The function writes the given data to the connected USB port. The default timeout is respected in this operation.
length | The number of bytes to write. |
data | A pointer to a memory buffer that contains the bytes to send |
written | An optional pointer to storage for the actual number of bytes that were written |
Definition at line 1028 of file usbinterface.cpp.
UsbInterface::XSENS_DISABLE_COPY | ( | UsbInterface | ) |
|
private |
Definition at line 91 of file usbinterface.h.