11 #include <mrpt/config.h> 124 int baudRate,
int parity = 0,
int bits = 8,
int nStopBits = 1,
125 bool enableFlowControl =
false);
131 int ReadIntervalTimeout,
int ReadTotalTimeoutMultiplier,
132 int ReadTotalTimeoutConstant,
int WriteTotalTimeoutMultiplier,
133 int WriteTotalTimeoutConstant);
141 size_t Read(
void* Buffer,
size_t Count);
156 const int total_timeout_ms = -1,
bool* out_timeout =
nullptr,
157 const char* eol_chars =
"\r\n");
164 size_t Write(
const void* Buffer,
size_t Count);
185 "Method not applicable to serial communications port CStream!");
195 "Method not applicable to serial communications port CStream!");
206 "Method not applicable to serial communications port CStream!");
221 #ifdef MRPT_OS_WINDOWS void open(const std::string &COM_name)
Open the given serial port.
void setSerialPortName(const std::string &COM_name)
Sets the serial port to open (it is an error to try to change this while open yet).
size_t Write(const void *Buffer, size_t Count)
Implements the virtual method responsible for writing to the stream.
A communications serial port built as an implementation of a utils::CStream.
uint64_t Seek(uint64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning)
Introduces a pure virtual method for moving to a specified position in the streamed resource...
std::string ReadString(const int total_timeout_ms=-1, bool *out_timeout=nullptr, const char *eol_chars="\")
Reads one text line from the serial port in POSIX "canonical mode".
uint64_t getPosition()
Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the l...
uint64_t getTotalBytesCount()
Returns the total amount of bytes in the stream.
#define THROW_EXCEPTION(msg)
void open()
Open the port.
void setConfig(int baudRate, int parity=0, int bits=8, int nStopBits=1, bool enableFlowControl=false)
Changes the configuration of the port.
mrpt::utils::CTicTac m_timer
Used only in ReadString.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
int m_interBytesTimeout_ms
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
This class implements a high-performance stopwatch.
bool isOpen() const
Returns if port has been correctly open.
void purgeBuffers()
Purge tx and rx buffers.
GLsizei const GLchar ** string
void close()
Close the port.
void setTimeouts(int ReadIntervalTimeout, int ReadTotalTimeoutMultiplier, int ReadTotalTimeoutConstant, int WriteTotalTimeoutMultiplier, int WriteTotalTimeoutConstant)
Changes the timeouts of the port, in milliseconds.
unsigned __int64 uint64_t
friend class PosixSignalDispatcherImpl
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string m_serialName
The complete name of the serial port device (i.e.
CSerialPort()
Default constructor: it does not open any port - later you must call "setSerialPortName" and then "op...
int hCOM
The file handle (-1: Not open)
size_t Read(void *Buffer, size_t Count)
Implements the virtual method responsible for reading from the stream - Unlike CStream::ReadBuffer, this method will not raise an exception on zero bytes read, as long as there is not any fatal error in the communications.
virtual ~CSerialPort()
Destructor.