101 lines
2.2 KiB
C++
101 lines
2.2 KiB
C++
#ifndef FA788814_8B75_424F_99DB_D04B4977DD8C
|
|
#define FA788814_8B75_424F_99DB_D04B4977DD8C
|
|
/*
|
|
*******************************************************************************
|
|
* INCLUDE
|
|
*******************************************************************************
|
|
*/
|
|
#include <Poco/Thread.h>
|
|
#include <atomic>
|
|
|
|
namespace Hardware
|
|
{
|
|
/*
|
|
*******************************************************************************
|
|
* CLASS DECLARE
|
|
*******************************************************************************
|
|
*/
|
|
class SerialPort
|
|
{
|
|
public:
|
|
enum class Parity
|
|
{
|
|
NONE,
|
|
ODD,
|
|
EVEN,
|
|
};
|
|
|
|
enum class FlowControl
|
|
{
|
|
NONE,
|
|
RTSCTS,
|
|
};
|
|
|
|
public:
|
|
SerialPort();
|
|
~SerialPort();
|
|
|
|
public:
|
|
SerialPort& setPath(const std::string& path);
|
|
SerialPort& setBaudRate(uint32_t baudRate);
|
|
SerialPort& setParity(Parity parity);
|
|
SerialPort& setDataBits(uint32_t bits);
|
|
SerialPort& setStopBits(uint32_t bits);
|
|
SerialPort& setFlowControl(FlowControl flowControl);
|
|
void open();
|
|
void close();
|
|
bool isOpen();
|
|
int write(const void* pData, uint32_t size);
|
|
int read(void* pBuffer, uint32_t length, uint32_t timeout);
|
|
|
|
const std::string& getPath();
|
|
uint32_t getBaudRate();
|
|
Parity getParity();
|
|
uint32_t getDataBits();
|
|
uint32_t getStopBits();
|
|
FlowControl getFlowControl();
|
|
|
|
protected:
|
|
uint32_t getBaudRateFlag(uint32_t baudRate);
|
|
|
|
private:
|
|
std::string _path;
|
|
int _fd;
|
|
uint32_t _baudRate;
|
|
Parity _parity;
|
|
uint32_t _dataBits;
|
|
uint32_t _stopBits;
|
|
FlowControl _flowControl;
|
|
};
|
|
|
|
inline const std::string& SerialPort::getPath()
|
|
{
|
|
return _path;
|
|
}
|
|
|
|
inline uint32_t SerialPort::getBaudRate()
|
|
{
|
|
return _baudRate;
|
|
}
|
|
|
|
inline SerialPort::Parity SerialPort::getParity()
|
|
{
|
|
return _parity;
|
|
}
|
|
|
|
inline uint32_t SerialPort::getDataBits()
|
|
{
|
|
return _dataBits;
|
|
}
|
|
|
|
inline uint32_t SerialPort::getStopBits()
|
|
{
|
|
return _stopBits;
|
|
}
|
|
|
|
inline SerialPort::FlowControl SerialPort::getFlowControl()
|
|
{
|
|
return _flowControl;
|
|
}
|
|
}
|
|
#endif
|