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

The low-level serial communication class. More...

#include <serialinterface.h>

Inheritance diagram for SerialInterface:
Inheritance graph
[legend]

Public Member Functions

void cancelIo (void) const
 Cancel any pending io requests. More...
 
XsResultValue close (void) override
 Close the serial communication port. More...
 
XsResultValue closeLive (void)
 Close the serial communication port. More...
 
XsResultValue escape (XsControlLine mask, XsControlLine state)
 Manipulate the Serial control lines. More...
 
XsResultValue flushData (void) override
 Flush all data in the buffers to and from the device. More...
 
XsBaudRate getBaudrate (void) const
 Return the baudrate that is currently being used by the port. More...
 
XsIoHandle getHandle (void) const
 Return the handle of the port. 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...
 
uint16_t getPortNumber (void) const
 Retrieve the port number that was last successfully opened. More...
 
uint32_t getTimeout (void) const
 Return the current timeout value. More...
 
bool isOpen (void) const
 Return whether the communication port is open or not. More...
 
XsResultValue open (const XsPortInfo &portInfo, XsFilePos readBufSize=XS_DEFAULT_READ_BUFFER_SIZE, XsFilePos writeBufSize=XS_DEFAULT_WRITE_BUFFER_SIZE, PortOptions options=PO_XsensDefaults) override
 Open a communication channel to the given port info. More...
 
XsResultValue readData (XsFilePos maxLength, XsByteArray &data) override
 Read data from the serial port and put it into the data buffer. More...
 
 SerialInterface ()
 Default constructor, initializes all members to their default values. More...
 
XsResultValue setTimeout (uint32_t ms)
 Set the default timeout value to use in blocking operations. More...
 
XsResultValue waitForData (XsFilePos maxLength, XsByteArray &data) override
 Wait for data to arrive or a timeout to occur. More...
 
XsResultValue writeData (const XsByteArray &data, XsFilePos *written=0) override
 Write the data contained in data to the device. More...
 
 XSENS_DISABLE_COPY (SerialInterface)
 
virtual ~SerialInterface ()
 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 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 ~IoInterface ()
 Destructor. More...
 

Protected Attributes

XsBaudRate m_baudrate
 The baudrate that was last set to be used by the port. More...
 
termios m_commState
 Stored settings about the serial port. More...
 
uint32_t m_endTime
 The time at which an operation will end in ms, used by several functions. More...
 
int32_t m_handle
 The serial port handle, also indicates if the port is open or not. More...
 
XsResultValue m_lastResult
 The last result of an operation. More...
 
uint16_t m_port
 The opened COM port nr. More...
 
char m_portname [32]
 The name of the open serial port. More...
 
uint32_t m_timeout
 

Private Member Functions

void applyHwControlLinesOptions (PortOptions options, int portLinesOptions, int &p)
 Apply the specified options for the hardware control lines. More...
 

Private Attributes

XsFile rx_log
 
XsFile tx_log
 

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

The low-level serial communication class.

Definition at line 82 of file serialinterface.h.

Constructor & Destructor Documentation

◆ SerialInterface()

SerialInterface::SerialInterface ( )

Default constructor, initializes all members to their default values.

Definition at line 99 of file serialinterface.cpp.

◆ ~SerialInterface()

SerialInterface::~SerialInterface ( )
virtual

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

Definition at line 116 of file serialinterface.cpp.

Member Function Documentation

◆ applyHwControlLinesOptions()

void SerialInterface::applyHwControlLinesOptions ( PortOptions  options,
int  portLinesOptions,
int &  p 
)
private

Apply the specified options for the hardware control lines.

Parameters
optionsThe options to enable (flow control, stop bits)
portLinesOptionsThe options for the hardware control lines (RTS/DTR levels)
pThe reference to an enabled bits

Definition at line 895 of file serialinterface.cpp.

◆ cancelIo()

void SerialInterface::cancelIo ( void  ) const
virtual

Cancel any pending io requests.

Reimplemented from IoInterface.

Definition at line 862 of file serialinterface.cpp.

◆ close()

XsResultValue SerialInterface::close ( void  )
overridevirtual

Close the serial communication port.

Implements IoInterface.

Definition at line 128 of file serialinterface.cpp.

◆ closeLive()

XsResultValue SerialInterface::closeLive ( void  )

Close the serial communication port.

Definition at line 134 of file serialinterface.cpp.

◆ escape()

XsResultValue SerialInterface::escape ( XsControlLine  mask,
XsControlLine  state 
)

Manipulate the Serial control lines.

The function manipulates the serial control lines that are indicated by the
mask parameter. Note that only the DTR and RTS lines can be set by win32.
\param mask         Indicates which lines are to be manipulated and which should be
                            left alone.
\param state        Contains the new state of the control lines.
\returns XRV_OK if the function succeeded

Definition at line 193 of file serialinterface.cpp.

◆ flushData()

XsResultValue SerialInterface::flushData ( void  )
overridevirtual

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

Returns
XRV_OK if the data was flushed successfully
Note
This function tries to send and receive any remaining data immediately and does not return until the buffers are empty.

Implements IoInterface.

Definition at line 258 of file serialinterface.cpp.

◆ getBaudrate()

XsBaudRate SerialInterface::getBaudrate ( void  ) const

Return the baudrate that is currently being used by the port.

Definition at line 273 of file serialinterface.cpp.

◆ getHandle()

XsIoHandle SerialInterface::getHandle ( void  ) const

Return the handle of the port.

Definition at line 281 of file serialinterface.cpp.

◆ getLastResult()

XsResultValue SerialInterface::getLastResult ( void  ) const
virtual

Return the error code of the last operation.

Implements IoInterface.

Definition at line 299 of file serialinterface.cpp.

◆ getPortName()

void SerialInterface::getPortName ( XsString portname) const

Retrieve the port name that was last successfully opened.

Definition at line 293 of file serialinterface.cpp.

◆ getPortNumber()

uint16_t SerialInterface::getPortNumber ( void  ) const

Retrieve the port number that was last successfully opened.

Definition at line 287 of file serialinterface.cpp.

◆ getTimeout()

uint32_t SerialInterface::getTimeout ( void  ) const
virtual

Return the current timeout value.

Implements StreamInterface.

Definition at line 305 of file serialinterface.cpp.

◆ isOpen()

bool SerialInterface::isOpen ( void  ) const
virtual

Return whether the communication port is open or not.

Implements IoInterface.

Definition at line 311 of file serialinterface.cpp.

◆ open()

XsResultValue SerialInterface::open ( const XsPortInfo portInfo,
XsFilePos  readBufSize = XS_DEFAULT_READ_BUFFER_SIZE,
XsFilePos  writeBufSize = XS_DEFAULT_WRITE_BUFFER_SIZE,
PortOptions  options = PO_XsensDefaults 
)
overridevirtual

Open a communication channel to the given port info.

If the baudrate in portInfo is set to XBR_Invalid, the baud rate is automatically detected if possible.

Parameters
portInfoThe details of the port that should be opened. Depending on the type of interface, parts of this parameter may be ignored.
readBufSizeThe size of the read buffer in bytes (if appliccable to the device)
writeBufSizeThe size of the write buffer in bytes (if appliccable to the device)
optionsThe options to enable (flow control, stop bits)
Returns
XRV_OK if the device was opened successfully

Reimplemented from IoInterface.

Definition at line 342 of file serialinterface.cpp.

◆ readData()

XsResultValue SerialInterface::readData ( XsFilePos  maxLength,
XsByteArray data 
)
overridevirtual

Read data from the serial 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 573 of file serialinterface.cpp.

◆ setTimeout()

XsResultValue SerialInterface::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 all blocking operations now become polling (non-blocking) operations. If the value is set to or from 0, the low-level serial port settings may be changed in addition to the m_timeout value.

Parameters
msThe new timeout in milliseconds
Returns
XRV_OK if the function succeeded

Implements StreamInterface.

Definition at line 697 of file serialinterface.cpp.

◆ waitForData()

XsResultValue SerialInterface::waitForData ( XsFilePos  maxLength,
XsByteArray data 
)
overridevirtual

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

Reimplemented from IoInterface.

Definition at line 751 of file serialinterface.cpp.

◆ writeData()

XsResultValue SerialInterface::writeData ( const XsByteArray data,
XsFilePos written = 0 
)
overridevirtual

Write the data contained in data to the device.

Parameters
dataThe data to write to the device.
writtenAn optional XsFilePos value that will receive the number of bytes that were actually written.
Returns
XRV_OK if the data was written successfully
Note
The default timeout is respected in this operation.

Implements IoInterface.

Definition at line 782 of file serialinterface.cpp.

◆ XSENS_DISABLE_COPY()

SerialInterface::XSENS_DISABLE_COPY ( SerialInterface  )

Member Data Documentation

◆ m_baudrate

XsBaudRate SerialInterface::m_baudrate
protected

The baudrate that was last set to be used by the port.

Definition at line 92 of file serialinterface.h.

◆ m_commState

termios SerialInterface::m_commState
protected

Stored settings about the serial port.

Definition at line 109 of file serialinterface.h.

◆ m_endTime

uint32_t SerialInterface::m_endTime
protected

The time at which an operation will end in ms, used by several functions.

Definition at line 94 of file serialinterface.h.

◆ m_handle

int32_t SerialInterface::m_handle
protected

The serial port handle, also indicates if the port is open or not.

Definition at line 110 of file serialinterface.h.

◆ m_lastResult

XsResultValue SerialInterface::m_lastResult
mutableprotected

The last result of an operation.

Definition at line 96 of file serialinterface.h.

◆ m_port

uint16_t SerialInterface::m_port
protected

The opened COM port nr.

Definition at line 98 of file serialinterface.h.

◆ m_portname

char SerialInterface::m_portname[32]
protected

The name of the open serial port.

Definition at line 100 of file serialinterface.h.

◆ m_timeout

uint32_t SerialInterface::m_timeout
protected

The default timeout value to use during blocking operations. A value of 0 means that all operations become non-blocking.

Definition at line 104 of file serialinterface.h.

◆ rx_log

XsFile SerialInterface::rx_log
private

Definition at line 88 of file serialinterface.h.

◆ tx_log

XsFile SerialInterface::tx_log
private

Definition at line 89 of file serialinterface.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