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
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:4050
unsigned __int16 uint16_t
Definition: rptypes.h:44
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:38
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:19
#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:27
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:46
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:51
GLsizei maxLength
Definition: glext.h:4932
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:47
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:3546
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.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020