Public Member Functions | Private Attributes | List of all members
UsbInterface Class Reference

An IoInterface for dealing specifically with Xsens USB devices. More...

#include <usbinterface.h>

Inheritance diagram for UsbInterface:
Inheritance graph
[legend]

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...
 
- Public Member Functions inherited from StreamInterface
 XSENS_DISABLE_COPY (StreamInterface)
 
 ~StreamInterface ()
 Destroy the stream interface. More...
 
- Public Member Functions inherited from IoInterface
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

UsbInterfacePrivated
 

Additional Inherited Members

- Public Types inherited from IoInterface
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...
 
- Protected Member Functions inherited from StreamInterface
 StreamInterface ()
 Create a stream interface. More...
 
- Protected Member Functions inherited from IoInterface
 IoInterface ()
 Constructor. More...
 
 XSENS_DISABLE_COPY (IoInterface)
 

Detailed Description

An IoInterface for dealing specifically with Xsens USB devices.

Definition at line 89 of file usbinterface.h.

Constructor & Destructor Documentation

◆ UsbInterface()

UsbInterface::UsbInterface ( )

Default constructor, initializes all members to their default values.

Definition at line 400 of file usbinterface.cpp.

◆ ~UsbInterface()

UsbInterface::~UsbInterface ( )

Destructor, de-initializes, frees memory allocated for buffers, etc.

Definition at line 429 of file usbinterface.cpp.

Member Function Documentation

◆ close()

XsResultValue UsbInterface::close ( void  )
virtual

Close the USB communication port.

Implements IoInterface.

Definition at line 449 of file usbinterface.cpp.

◆ closeUsb()

XsResultValue UsbInterface::closeUsb ( void  )

Close the USB communication port.

Returns
XRV_OK if the port was closed successfully
Note
Linux:
If a kernel driver was detached when communication with the device started, attach it again. No guarantee is given that udev will pick up on it though.

Definition at line 460 of file usbinterface.cpp.

◆ flushData()

XsResultValue UsbInterface::flushData ( void  )
virtual

Flush all data in the buffers to and from the device.

Returns
XRV_OK if the data was flushed successfully

Implements IoInterface.

Definition at line 529 of file usbinterface.cpp.

◆ getLastResult()

XsResultValue UsbInterface::getLastResult ( void  ) const
virtual

Return the error code of the last operation.

Implements IoInterface.

Definition at line 566 of file usbinterface.cpp.

◆ getPortName()

void UsbInterface::getPortName ( XsString portname) const

Retrieve the port name that was last successfully opened.

Definition at line 1112 of file usbinterface.cpp.

◆ getRawIo()

bool UsbInterface::getRawIo ( void  )

Retrieves the state of the RAWIO mode of the USB interface.

Returns
true if raw IO mode is enabled
Note
Only applies to WinUSB implementations

Definition at line 955 of file usbinterface.cpp.

◆ getTimeout()

uint32_t UsbInterface::getTimeout ( void  ) const
virtual

Return the current timeout value.

Implements StreamInterface.

Definition at line 572 of file usbinterface.cpp.

◆ isOpen()

bool UsbInterface::isOpen ( void  ) const
virtual

Return whether the USB communication port is open or not.

Implements IoInterface.

Definition at line 578 of file usbinterface.cpp.

◆ open()

XsResultValue UsbInterface::open ( const XsPortInfo portInfo,
XsFilePos  readBufSize = 0,
XsFilePos  writeBufSize = 0,
PortOptions  = PO_XsensDefaults 
)
overridevirtual

Open a communication channel to the given USB port name.

Reimplemented from IoInterface.

Definition at line 584 of file usbinterface.cpp.

◆ readData() [1/2]

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.

Parameters
maxLengthThe maximum number of bytes to read.
dataPointer to a buffer that will store the received data.
lengthThe number of bytes placed into data.
Returns
XRV_OK if no error occurred. It can be that no data is available and XRV_OK will be returned. Check *length for the number of bytes that were read.

Definition at line 842 of file usbinterface.cpp.

◆ readData() [2/2]

XsResultValue UsbInterface::readData ( XsFilePos  maxLength,
XsByteArray data 
)
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.

Parameters
maxLengthThe maximum amount of data read.
dataThe buffer that will store the received data.
Returns
XRV_OK if no error occurred. It can be that no data is available and XRV_OK will be returned. Check data.size() for the number of bytes that were read.

Implements IoInterface.

Definition at line 824 of file usbinterface.cpp.

◆ setRawIo()

void UsbInterface::setRawIo ( bool  enable)

Sets the RAWIO mode of the USB interface.

Note
Only applies to WinUSB implementations
Parameters
enable: If true will enable RAW IO mode

Definition at line 937 of file usbinterface.cpp.

◆ setTimeout()

XsResultValue UsbInterface::setTimeout ( uint32_t  ms)
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.

Parameters
msThe desired timeout in milliseconds
Returns
XRV_OK if the timeout value was successfully updated

Implements StreamInterface.

Definition at line 912 of file usbinterface.cpp.

◆ usbAddress()

uint8_t UsbInterface::usbAddress ( ) const

The address of the device (libusb/linux only)

Definition at line 1098 of file usbinterface.cpp.

◆ usbBus()

uint8_t UsbInterface::usbBus ( ) const

The USB bus number this device is on (libusb/linux only)

Definition at line 1084 of file usbinterface.cpp.

◆ waitForData() [1/2]

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.

Parameters
maxLengthThe maximum number of bytes to wait for
dataA buffer that will be filled with the read data. It must be able to contain at least maxLength bytes.
lengthAn optional pointer to storage for the actual number of bytes read.
Returns
XRV_OK if the requested data was read

Definition at line 978 of file usbinterface.cpp.

◆ waitForData() [2/2]

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.

Parameters
maxLengthThe maximum number of bytes to read before returning
dataThe buffer to put the read data in.
Returns
XRV_OK if maxLength bytes were read, XRV_TIMEOUT if less was read, XRV_TIMEOUTNODATA if nothing was read

Definition at line 107 of file iointerface.cpp.

◆ writeData() [1/2]

XsResultValue UsbInterface::writeData ( const XsByteArray data,
XsFilePos written = NULL 
)
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.

Parameters
dataThe data to be written
writtenAn optional pointer to storage for the actual number of bytes that were written
Returns
XRV_OK if the data was successfully written
See also
writeData(XsFilePos, const void *, XsFilePos*)

Implements IoInterface.

Definition at line 1014 of file usbinterface.cpp.

◆ writeData() [2/2]

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.

Parameters
lengthThe number of bytes to write.
dataA pointer to a memory buffer that contains the bytes to send
writtenAn optional pointer to storage for the actual number of bytes that were written
Returns
XRV_OK if the data was successfully written
See also
writeData(const XsByteArray&, XsFilePos*)

Definition at line 1028 of file usbinterface.cpp.

◆ XSENS_DISABLE_COPY()

UsbInterface::XSENS_DISABLE_COPY ( UsbInterface  )

Member Data Documentation

◆ d

UsbInterfacePrivate* UsbInterface::d
private

Definition at line 91 of file usbinterface.h.


The documentation for this class was generated from the following files:


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:22