The low-level serial communication class. More...
#include <serialinterface.h>
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... | |
![]() | |
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 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 | |
![]() | |
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) | |
The low-level serial communication class.
Definition at line 82 of file serialinterface.h.
SerialInterface::SerialInterface | ( | ) |
Default constructor, initializes all members to their default values.
Definition at line 99 of file serialinterface.cpp.
|
virtual |
Destructor, de-initializes, frees memory allocated for buffers, etc.
Definition at line 116 of file serialinterface.cpp.
|
private |
Apply the specified options for the hardware control lines.
options | The options to enable (flow control, stop bits) |
portLinesOptions | The options for the hardware control lines (RTS/DTR levels) |
p | The reference to an enabled bits |
Definition at line 895 of file serialinterface.cpp.
|
virtual |
Cancel any pending io requests.
Reimplemented from IoInterface.
Definition at line 862 of file serialinterface.cpp.
|
overridevirtual |
Close the serial communication port.
Implements IoInterface.
Definition at line 128 of file serialinterface.cpp.
XsResultValue SerialInterface::closeLive | ( | void | ) |
Close the serial communication port.
Definition at line 134 of file serialinterface.cpp.
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.
|
overridevirtual |
Flush all data in the buffers to and from the device.
Implements IoInterface.
Definition at line 258 of file serialinterface.cpp.
XsBaudRate SerialInterface::getBaudrate | ( | void | ) | const |
Return the baudrate that is currently being used by the port.
Definition at line 273 of file serialinterface.cpp.
XsIoHandle SerialInterface::getHandle | ( | void | ) | const |
Return the handle of the port.
Definition at line 281 of file serialinterface.cpp.
|
virtual |
Return the error code of the last operation.
Implements IoInterface.
Definition at line 299 of file serialinterface.cpp.
void SerialInterface::getPortName | ( | XsString & | portname | ) | const |
Retrieve the port name that was last successfully opened.
Definition at line 293 of file serialinterface.cpp.
uint16_t SerialInterface::getPortNumber | ( | void | ) | const |
Retrieve the port number that was last successfully opened.
Definition at line 287 of file serialinterface.cpp.
|
virtual |
Return the current timeout value.
Implements StreamInterface.
Definition at line 305 of file serialinterface.cpp.
|
virtual |
Return whether the communication port is open or not.
Implements IoInterface.
Definition at line 311 of file serialinterface.cpp.
|
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.
portInfo | The details of the port that should be opened. Depending on the type of interface, parts of this parameter may be ignored. |
readBufSize | The size of the read buffer in bytes (if appliccable to the device) |
writeBufSize | The size of the write buffer in bytes (if appliccable to the device) |
options | The options to enable (flow control, stop bits) |
Reimplemented from IoInterface.
Definition at line 342 of file serialinterface.cpp.
|
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.
maxLength | The maximum amount of data read. |
data | The buffer that will store the received data. |
Implements IoInterface.
Definition at line 573 of file serialinterface.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 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.
ms | The new timeout in milliseconds |
Implements StreamInterface.
Definition at line 697 of file serialinterface.cpp.
|
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.
maxLength | The maximum number of bytes to read before returning |
data | The buffer to put the read data in. |
Reimplemented from IoInterface.
Definition at line 751 of file serialinterface.cpp.
|
overridevirtual |
Write the data contained in data to the device.
data | The data to write to the device. |
written | An optional XsFilePos value that will receive the number of bytes that were actually written. |
Implements IoInterface.
Definition at line 782 of file serialinterface.cpp.
SerialInterface::XSENS_DISABLE_COPY | ( | SerialInterface | ) |
|
protected |
The baudrate that was last set to be used by the port.
Definition at line 92 of file serialinterface.h.
|
protected |
Stored settings about the serial port.
Definition at line 109 of file serialinterface.h.
|
protected |
The time at which an operation will end in ms, used by several functions.
Definition at line 94 of file serialinterface.h.
|
protected |
The serial port handle, also indicates if the port is open or not.
Definition at line 110 of file serialinterface.h.
|
mutableprotected |
The last result of an operation.
Definition at line 96 of file serialinterface.h.
|
protected |
The opened COM port nr.
Definition at line 98 of file serialinterface.h.
|
protected |
The name of the open serial port.
Definition at line 100 of file serialinterface.h.
|
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.
|
private |
Definition at line 88 of file serialinterface.h.
|
private |
Definition at line 89 of file serialinterface.h.