Main MRPT website > C++ reference for MRPT 1.9.9
serialinterface.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef SERIALINTERFACE_H
10 #define SERIALINTERFACE_H
11 
12 #include "streaminterface.h"
13 #include <xsens/xsplatform.h>
14 #include <xsens/xsmessage.h>
15 #include <xsens/xsbaud.h>
16 #include <xsens/xscontrolline.h>
17 
18 struct XsPortInfo;
19 
20 //////////////////////////////////////////////////////////////////////////////////////////
21 ///////////////////////////////////////// SerialInterface
22 ////////////////////////////////////////////
23 //////////////////////////////////////////////////////////////////////////////////////////
24 
25 /*! \brief The low-level serial communication class.
26 */
28 {
29  private:
31 
34 
35  protected:
36  //! The baudrate that was last set to be used by the port
38  //! The time at which an operation will end in ms, used by several
39  //! functions.
41  //! The last result of an operation
43  //! The opened COM port nr
45  //! The name of the open serial port
46  char m_portname[32];
47  /*! The default timeout value to use during blocking operations.
48  A value of 0 means that all operations become non-blocking.
49  */
51 
52 #ifdef _WIN32
53  /** The serial port handle, also indicates if the port is open or not. */
55 #else
56  /** Stored settings about the serial port */
57  termios m_commState;
58  /** The serial port handle, also indicates if the port is open or not. */
60 #endif
61  public:
63  virtual ~SerialInterface();
64 
65  // Function overrides
66  XsResultValue close(void);
69  bool isOpen(void) const;
70  XsResultValue getLastResult(void) const;
71  XsResultValue writeData(const XsByteArray& data, XsSize* written = 0);
73 
74  void cancelIo(void) const;
75 
76  // Other functions
78  XsBaudRate getBaudrate(void) const;
79  XsIoHandle getHandle(void) const;
80  uint16_t getPortNumber(void) const;
81  void getPortName(XsString& portname) const;
82  uint32_t getTimeout(void) const;
84  const XsPortInfo& portInfo,
86  uint32_t writeBufSize = XS_DEFAULT_WRITE_BUFFER_SIZE);
89 };
90 
91 #endif // file guard
XsString
struct XsString XsString
Definition: xsstring.h:34
XsIoHandle
HANDLE XsIoHandle
Definition: xsfilepos.h:38
maxLength
GLsizei maxLength
Definition: glext.h:4932
SerialInterface::writeData
XsResultValue writeData(const XsByteArray &data, XsSize *written=0)
Write the data contained in data to the device.
Definition: serialinterface.cpp:702
SerialInterface::m_timeout
uint32_t m_timeout
Definition: serialinterface.h:50
SerialInterface::m_handle
XsIoHandle m_handle
The serial port handle, also indicates if the port is open or not.
Definition: serialinterface.h:54
XsPortInfo
Definition: xsportinfo.h:46
SerialInterface::isOpen
bool isOpen(void) const
Return whether the communication port is open or not.
Definition: serialinterface.cpp:259
XsByteArray
struct XsByteArray XsByteArray
Definition: xsbytearray.h:25
uint16_t
unsigned __int16 uint16_t
Definition: rptypes.h:44
SerialInterface::m_port
uint16_t m_port
The opened COM port nr.
Definition: serialinterface.h:44
SerialInterface::readData
XsResultValue readData(XsSize maxLength, XsByteArray &data)
Read data from the serial port and put it into the data buffer.
Definition: serialinterface.cpp:517
XsControlLine
XsControlLine
Serial control lines.
Definition: xscontrolline.h:16
SerialInterface::getPortNumber
uint16_t getPortNumber(void) const
Retrieve the port number that was last successfully opened.
Definition: serialinterface.cpp:245
SerialInterface::rx_log
XsFileHandle * rx_log
Definition: serialinterface.h:32
XsFileHandle
FILE XsFileHandle
Definition: xsfilepos.h:51
SerialInterface::m_baudrate
XsBaudRate m_baudrate
The baudrate that was last set to be used by the port.
Definition: serialinterface.h:37
xsplatform.h
SerialInterface::m_portname
char m_portname[32]
The name of the open serial port.
Definition: serialinterface.h:46
SerialInterface::cancelIo
void cancelIo(void) const
Cancel any pending io requests.
Definition: serialinterface.cpp:755
XsBaudRate
XsBaudRate
Communication speed.
Definition: xsbaudrate.h:27
SerialInterface::~SerialInterface
virtual ~SerialInterface()
Destructor, de-initializes, frees memory allocated for buffers, etc.
Definition: serialinterface.cpp:80
SerialInterface::m_lastResult
XsResultValue m_lastResult
The last result of an operation.
Definition: serialinterface.h:42
XS_DEFAULT_READ_BUFFER_SIZE
#define XS_DEFAULT_READ_BUFFER_SIZE
The default size of the serial read buffer in bytes.
Definition: iointerface.h:23
XsResultValue
XsResultValue
Xsens result values.
Definition: xsresultvalue.h:27
SerialInterface::escape
XsResultValue escape(XsControlLine mask, XsControlLine state)
Manipulate the Serial control lines.
Definition: serialinterface.cpp:156
streaminterface.h
XS_DEFAULT_WRITE_BUFFER_SIZE
#define XS_DEFAULT_WRITE_BUFFER_SIZE
The default size of the serial write buffer in bytes.
Definition: iointerface.h:25
data
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3547
StreamInterface
A stream interface.
Definition: streaminterface.h:21
SerialInterface::getHandle
XsIoHandle getHandle(void) const
Return the handle of the port.
Definition: serialinterface.cpp:243
SerialInterface::getBaudrate
XsBaudRate getBaudrate(void) const
Return the baudrate that is currently being used by the port.
Definition: serialinterface.cpp:237
SerialInterface::closeLive
XsResultValue closeLive(void)
Close the serial communication port.
Definition: serialinterface.cpp:94
SerialInterface::setTimeout
XsResultValue setTimeout(uint32_t ms)
Set the default timeout value to use in blocking operations.
Definition: serialinterface.cpp:610
XsSize
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:19
mask
GLenum GLint GLuint mask
Definition: glext.h:4050
SerialInterface::flushData
XsResultValue flushData(void)
Flush all data in the buffers to and from the device.
Definition: serialinterface.cpp:222
xscontrolline.h
SerialInterface::getLastResult
XsResultValue getLastResult(void) const
Return the error code of the last operation.
Definition: serialinterface.cpp:252
SerialInterface::open
XsResultValue open(const XsPortInfo &portInfo, uint32_t readBufSize=XS_DEFAULT_READ_BUFFER_SIZE, uint32_t writeBufSize=XS_DEFAULT_WRITE_BUFFER_SIZE)
Open a communication channel to the given port info.
Definition: serialinterface.cpp:281
XSENS_DISABLE_COPY
#define XSENS_DISABLE_COPY(className)
Add this macro to the start of a class definition to prevent automatic creation of copy functions.
Definition: xcommunicationconfig.h:149
SerialInterface::getTimeout
uint32_t getTimeout(void) const
Return the current timeout value.
Definition: serialinterface.cpp:257
int32_t
__int32 int32_t
Definition: rptypes.h:46
SerialInterface::waitForData
XsResultValue waitForData(XsSize maxLength, XsByteArray &data)
Wait for data to arrive or a timeout to occur.
Definition: serialinterface.cpp:669
SerialInterface::close
XsResultValue close(void)
Close the serial communication port.
Definition: serialinterface.cpp:92
xsmessage.h
xsbaud.h
SerialInterface
The low-level serial communication class.
Definition: serialinterface.h:27
SerialInterface::m_endTime
uint32_t m_endTime
The time at which an operation will end in ms, used by several functions.
Definition: serialinterface.h:40
SerialInterface::tx_log
XsFileHandle * tx_log
Definition: serialinterface.h:33
SerialInterface::getPortName
void getPortName(XsString &portname) const
Retrieve the port name that was last successfully opened.
Definition: serialinterface.cpp:247
uint32_t
unsigned __int32 uint32_t
Definition: rptypes.h:47
SerialInterface::SerialInterface
SerialInterface()
Default constructor, initializes all members to their default values.
Definition: serialinterface.cpp:60



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST