MRPT  1.9.9
serialinterface.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef SERIALINTERFACE_H
10 #define SERIALINTERFACE_H
11 
12 #include <xsens/xsbaud.h>
13 #include <xsens/xscontrolline.h>
14 #include <xsens/xsmessage.h>
15 #include <xsens/xsplatform.h>
16 #include "streaminterface.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  ~SerialInterface() override;
64 
65  // Function overrides
66  XsResultValue close(void) override;
68  XsResultValue flushData(void) override;
69  bool isOpen(void) const override;
70  XsResultValue getLastResult(void) const override;
72  const XsByteArray& data, XsSize* written = 0) override;
74 
75  void cancelIo(void) const override;
76 
77  // Other functions
79  XsBaudRate getBaudrate(void) const;
80  XsIoHandle getHandle(void) const;
81  uint16_t getPortNumber(void) const;
82  void getPortName(XsString& portname) const;
83  uint32_t getTimeout(void) const override;
85  const XsPortInfo& portInfo,
87  uint32_t writeBufSize = XS_DEFAULT_WRITE_BUFFER_SIZE) override;
88  XsResultValue setTimeout(uint32_t ms) override;
90 };
91 
92 #endif // file guard
bool isOpen(void) const override
Return whether the communication port is open or not.
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:4062
unsigned __int16 uint16_t
Definition: rptypes.h:47
XsResultValue readData(XsSize maxLength, XsByteArray &data) override
Read data from the serial port and put it into the data buffer.
uint16_t m_port
The opened COM port nr.
XsFileHandle * rx_log
XsResultValue flushData(void) override
Flush all data in the buffers to and from the device.
HANDLE XsIoHandle
Definition: xsfilepos.h:38
A stream interface.
struct XsByteArray XsByteArray
Definition: xsbytearray.h:26
XsControlLine
Serial control lines.
Definition: xscontrolline.h:16
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:19
XsResultValue setTimeout(uint32_t ms) override
Set the default timeout value to use in blocking operations.
#define XS_DEFAULT_WRITE_BUFFER_SIZE
The default size of the serial write buffer in bytes.
Definition: iointerface.h:25
XsBaudRate getBaudrate(void) const
Return the baudrate that is currently being used by the port.
XsResultValue
Xsens result values.
Definition: xsresultvalue.h:28
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.
XsResultValue m_lastResult
The last result of an operation.
void cancelIo(void) const override
Cancel any pending io requests.
#define XSENS_DISABLE_COPY(className)
Add this macro to the start of a class definition to prevent automatic creation of copy functions...
__int32 int32_t
Definition: rptypes.h:49
XsIoHandle getHandle(void) const
Return the handle of the port.
XsResultValue open(const XsPortInfo &portInfo, uint32_t readBufSize=XS_DEFAULT_READ_BUFFER_SIZE, uint32_t writeBufSize=XS_DEFAULT_WRITE_BUFFER_SIZE) override
Open a communication channel to the given port info.
The low-level serial communication class.
XsFileHandle * tx_log
uint32_t getTimeout(void) const override
Return the current timeout value.
XsResultValue close(void) override
Close the serial communication port.
uint32_t m_endTime
The time at which an operation will end in ms, used by several functions.
FILE XsFileHandle
Definition: xsfilepos.h:51
~SerialInterface() override
Destructor, de-initializes, frees memory allocated for buffers, etc.
XsResultValue writeData(const XsByteArray &data, XsSize *written=0) override
Write the data contained in data to the device.
GLsizei maxLength
Definition: glext.h:4991
void getPortName(XsString &portname) const
Retrieve the port name that was last successfully opened.
struct XsString XsString
Definition: xsstring.h:35
unsigned __int32 uint32_t
Definition: rptypes.h:50
XsBaudRate
Communication speed.
Definition: xsbaudrate.h:27
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3550
XsResultValue getLastResult(void) const override
Return the error code of the last operation.
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
XsResultValue waitForData(XsSize maxLength, XsByteArray &data) override
Wait for data to arrive or a timeout to occur.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019