serialinterface.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #ifndef SERIALINTERFACE_H
66 #define SERIALINTERFACE_H
67 
68 #include "streaminterface.h"
69 #include <xstypes/xsplatform.h>
70 #include <xstypes/xsmessage.h>
71 #include <xstypes/xsbaud.h>
72 #include <xstypes/xscontrolline.h>
73 
74 struct XsPortInfo;
75 
79 
83 {
84 private:
85  void applyHwControlLinesOptions(PortOptions options, int portLinesOptions, int& p);
86 
87  // these are only used when LOG_RX_TX is defined in rx_tx_log.h
90 protected:
98  uint16_t m_port;
100  char m_portname[32];
105 
106 #ifdef _WIN32
108 #else
109  termios m_commState;
111 #endif
112 public:
113  SerialInterface();
114  virtual ~SerialInterface();
115 
116  // Function overrides
117  XsResultValue close(void) override;
118  XsResultValue closeLive(void);
119  XsResultValue flushData(void) override;
120  bool isOpen(void) const;
121  XsResultValue getLastResult(void) const;
122  XsResultValue writeData(const XsByteArray& data, XsFilePos* written = 0) override;
123  XsResultValue readData(XsFilePos maxLength, XsByteArray& data) override;
124 
125  void cancelIo(void) const;
126 
127  // Other functions
129  XsBaudRate getBaudrate(void) const;
130  XsIoHandle getHandle(void) const;
131  uint16_t getPortNumber(void) const;
132  void getPortName(XsString& portname) const;
133  uint32_t getTimeout(void) const;
134 
137  XsResultValue waitForData(XsFilePos maxLength, XsByteArray& data) override;
138 
140 };
141 
145 
146 #endif
XsIoHandle
int32_t XsIoHandle
The type that is used for low-level identification of an open I/O device.
Definition: xsfilepos.h:104
SerialInterface::getPortName
void getPortName(XsString &portname) const
Retrieve the port name that was last successfully opened.
Definition: serialinterface.cpp:293
SerialInterface::getPortNumber
uint16_t getPortNumber(void) const
Retrieve the port number that was last successfully opened.
Definition: serialinterface.cpp:287
SerialInterface::m_port
uint16_t m_port
The opened COM port nr.
Definition: serialinterface.h:98
XsByteArray
A list of uint8_t values.
SerialInterface::setTimeout
XsResultValue setTimeout(uint32_t ms)
Set the default timeout value to use in blocking operations.
Definition: serialinterface.cpp:697
SerialInterface::close
XsResultValue close(void) override
Close the serial communication port.
Definition: serialinterface.cpp:128
XsControlLine
XsControlLine
Serial control lines.
Definition: xscontrolline.h:72
StreamInterface
A stream interface.
Definition: streaminterface.h:75
operator|
SerialInterface::PortOptions operator|(SerialInterface::PortOptions lhs, SerialInterface::PortOptions rhs)
Logical or operator for flow controls.
Definition: serialinterface.cpp:873
SerialInterface::m_endTime
uint32_t m_endTime
The time at which an operation will end in ms, used by several functions.
Definition: serialinterface.h:94
xsplatform.h
SerialInterface::m_baudrate
XsBaudRate m_baudrate
The baudrate that was last set to be used by the port.
Definition: serialinterface.h:92
SerialInterface::getLastResult
XsResultValue getLastResult(void) const
Return the error code of the last operation.
Definition: serialinterface.cpp:299
SerialInterface::readData
XsResultValue readData(XsFilePos maxLength, XsByteArray &data) override
Read data from the serial port and put it into the data buffer.
Definition: serialinterface.cpp:573
IoInterface::PortOptions
PortOptions
Options for flow control and stopbits which must be used when opening a port.
Definition: iointerface.h:130
XS_DEFAULT_READ_BUFFER_SIZE
#define XS_DEFAULT_READ_BUFFER_SIZE
The default size of the serial read buffer in bytes.
Definition: iointerface.h:80
XsResultValue
XsResultValue
Xsens result values.
Definition: xsresultvalue.h:82
streaminterface.h
SerialInterface::m_lastResult
XsResultValue m_lastResult
The last result of an operation.
Definition: serialinterface.h:96
XS_DEFAULT_WRITE_BUFFER_SIZE
#define XS_DEFAULT_WRITE_BUFFER_SIZE
The default size of the serial write buffer in bytes.
Definition: iointerface.h:82
SerialInterface::closeLive
XsResultValue closeLive(void)
Close the serial communication port.
Definition: serialinterface.cpp:134
XsBaudRate
enum XsBaudRate XsBaudRate
Communication speed.
Definition: xsbaud.h:81
uint32_t
unsigned int uint32_t
Definition: pstdint.h:485
SerialInterface::~SerialInterface
virtual ~SerialInterface()
Destructor, de-initializes, frees memory allocated for buffers, etc.
Definition: serialinterface.cpp:116
XsPortInfo
Contains a descriptor for opening a communication port to an Xsens device.
Definition: xsportinfo.h:128
SerialInterface::getBaudrate
XsBaudRate getBaudrate(void) const
Return the baudrate that is currently being used by the port.
Definition: serialinterface.cpp:273
IoInterface::PO_XsensDefaults
@ PO_XsensDefaults
Definition: iointerface.h:138
SerialInterface::applyHwControlLinesOptions
void applyHwControlLinesOptions(PortOptions options, int portLinesOptions, int &p)
Apply the specified options for the hardware control lines.
Definition: serialinterface.cpp:895
SerialInterface::tx_log
XsFile tx_log
Definition: serialinterface.h:89
xscontrolline.h
SerialInterface::open
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.
Definition: serialinterface.cpp:342
SerialInterface::flushData
XsResultValue flushData(void) override
Flush all data in the buffers to and from the device.
Definition: serialinterface.cpp:258
SerialInterface::getHandle
XsIoHandle getHandle(void) const
Return the handle of the port.
Definition: serialinterface.cpp:281
SerialInterface::SerialInterface
SerialInterface()
Default constructor, initializes all members to their default values.
Definition: serialinterface.cpp:99
SerialInterface::escape
XsResultValue escape(XsControlLine mask, XsControlLine state)
Manipulate the Serial control lines.
Definition: serialinterface.cpp:193
SerialInterface::cancelIo
void cancelIo(void) const
Cancel any pending io requests.
Definition: serialinterface.cpp:862
SerialInterface
The low-level serial communication class.
Definition: serialinterface.h:82
XsFile
Encapsulates a file, providing a platform independent interface.
Definition: xsfile.h:131
SerialInterface::isOpen
bool isOpen(void) const
Return whether the communication port is open or not.
Definition: serialinterface.cpp:311
xsmessage.h
SerialInterface::writeData
XsResultValue writeData(const XsByteArray &data, XsFilePos *written=0) override
Write the data contained in data to the device.
Definition: serialinterface.cpp:782
xsbaud.h
SerialInterface::waitForData
XsResultValue waitForData(XsFilePos maxLength, XsByteArray &data) override
Wait for data to arrive or a timeout to occur.
Definition: serialinterface.cpp:751
SerialInterface::m_timeout
uint32_t m_timeout
Definition: serialinterface.h:104
SerialInterface::XSENS_DISABLE_COPY
XSENS_DISABLE_COPY(SerialInterface)
operator&
SerialInterface::PortOptions operator&(SerialInterface::PortOptions lhs, SerialInterface::PortOptions rhs)
Logical and operator for flow controls.
Definition: serialinterface.cpp:879
int32_t
signed int int32_t
Definition: pstdint.h:515
SerialInterface::getTimeout
uint32_t getTimeout(void) const
Return the current timeout value.
Definition: serialinterface.cpp:305
SerialInterface::rx_log
XsFile rx_log
Definition: serialinterface.h:88
SerialInterface::m_commState
termios m_commState
Stored settings about the serial port.
Definition: serialinterface.h:109
operator~
SerialInterface::PortOptions operator~(SerialInterface::PortOptions lhs)
Logical inversion operator for flow controls.
Definition: serialinterface.cpp:885
SerialInterface::m_handle
int32_t m_handle
The serial port handle, also indicates if the port is open or not.
Definition: serialinterface.h:110
XsFilePos
int64_t XsFilePos
The type that is used for positioning inside a file.
Definition: xsfilepos.h:102
XsString
A 0-terminated managed string of characters.
SerialInterface::m_portname
char m_portname[32]
The name of the open serial port.
Definition: serialinterface.h:100


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20