Main MRPT website > C++ reference for MRPT 1.5.6
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-2017, 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 /*! \brief The low-level serial communication class.
25 */
27 private:
29 
32 
33 protected:
34  //! The baudrate that was last set to be used by the port
36  //! The time at which an operation will end in ms, used by several functions.
38  //! The last result of an operation
40  //! The opened COM port nr
42  //! The name of the open serial port
43  char m_portname[32];
44  /*! The default timeout value to use during blocking operations.
45  A value of 0 means that all operations become non-blocking.
46  */
48 
49  #ifdef _WIN32
50  XsIoHandle m_handle; //!< The serial port handle, also indicates if the port is open or not.
51  #else
52  termios m_commState; //!< Stored settings about the serial port
53  int32_t m_handle; //!< The serial port handle, also indicates if the port is open or not.
54  #endif
55 public:
57  virtual ~SerialInterface();
58 
59  // Function overrides
60  XsResultValue close (void);
62  XsResultValue flushData (void);
63  bool isOpen (void) const;
64  XsResultValue getLastResult(void) const;
65  XsResultValue writeData (const XsByteArray& data, XsSize* written = 0);
67 
68  void cancelIo(void) const;
69 
70  // Other functions
72  XsBaudRate getBaudrate(void) const;
73  XsIoHandle getHandle(void) const;
74  uint16_t getPortNumber (void) const;
75  void getPortName(XsString& portname) const;
76  uint32_t getTimeout (void) const;
80 };
81 
82 #endif // file guard
XsIoHandle m_handle
The serial port handle, also indicates if the port is open or not.
uint16_t getPortNumber(void) const
Retrieve the port number that was last successfully opened.
GLenum GLint GLuint mask
Definition: glext.h:3888
unsigned __int16 uint16_t
Definition: rptypes.h:46
uint16_t m_port
The opened COM port nr.
XsFileHandle * rx_log
bool isOpen(void) const
Return whether the communication port is open or not.
HANDLE XsIoHandle
Definition: xsfilepos.h:37
A stream interface.
struct XsByteArray XsByteArray
Definition: xsbytearray.h:25
XsControlLine
Serial control lines.
Definition: xscontrolline.h:16
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:17
#define XS_DEFAULT_WRITE_BUFFER_SIZE
The default size of the serial write buffer in bytes.
Definition: iointerface.h:25
XsResultValue readData(XsSize maxLength, XsByteArray &data)
Read data from the serial port and put it into the data buffer.
XsBaudRate getBaudrate(void) const
Return the baudrate that is currently being used by the port.
XsResultValue
Xsens result values.
Definition: xsresultvalue.h:26
XsBaudRate m_baudrate
The baudrate that was last set to be used by the port.
char m_portname[32]
The name of the open serial port.
XsResultValue escape(XsControlLine mask, XsControlLine state)
Manipulate the Serial control lines.
XsResultValue closeLive(void)
Close the serial communication port.
void cancelIo(void) const
Cancel any pending io requests.
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.
XsResultValue m_lastResult
The last result of an operation.
virtual ~SerialInterface()
Destructor, de-initializes, frees memory allocated for buffers, etc.
#define XSENS_DISABLE_COPY(className)
Add this macro to the start of a class definition to prevent automatic creation of copy functions...
XsResultValue getLastResult(void) const
Return the error code of the last operation.
__int32 int32_t
Definition: rptypes.h:48
XsIoHandle getHandle(void) const
Return the handle of the port.
The low-level serial communication class.
XsResultValue flushData(void)
Flush all data in the buffers to and from the device.
XsFileHandle * tx_log
XsResultValue setTimeout(uint32_t ms)
Set the default timeout value to use in blocking operations.
uint32_t getTimeout(void) const
Return the current timeout value.
uint32_t m_endTime
The time at which an operation will end in ms, used by several functions.
FILE XsFileHandle
Definition: xsfilepos.h:50
GLsizei maxLength
Definition: glext.h:4504
void getPortName(XsString &portname) const
Retrieve the port name that was last successfully opened.
XsResultValue waitForData(XsSize maxLength, XsByteArray &data)
Wait for data to arrive or a timeout to occur.
struct XsString XsString
Definition: xsstring.h:34
XsResultValue close(void)
Close the serial communication port.
unsigned __int32 uint32_t
Definition: rptypes.h:49
XsResultValue writeData(const XsByteArray &data, XsSize *written=0)
Write the data contained in data to the device.
XsBaudRate
Communication speed.
Definition: xsbaudrate.h:27
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3520
SerialInterface()
Default constructor, initializes all members to their default values.
#define XS_DEFAULT_READ_BUFFER_SIZE
The default size of the serial read buffer in bytes.
Definition: iointerface.h:23



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019