HLR  0.0.1
Serial.hpp
1 #ifndef KINEMATICS_RV2AJ_DRIVER_SERIAL_HPP
2 #define KINEMATICS_RV2AJ_DRIVER_SERIAL_HPP
3 
4 #include <memory>
5 #include <string>
6 
7 namespace HLR
8 {
9 namespace Kinematics
10 {
11 namespace RV2AJ
12 {
14 class Serial
15 {
16 public:
18  Serial() = default;
19 
24  virtual ~Serial();
25 
30  Serial(const Serial& s) = delete;
31 
36  Serial(Serial&& s) = delete;
37 
43  Serial& operator=(const Serial& s) = delete;
44 
50  Serial& operator=(Serial&& s) = delete;
51 
62  void open(const std::string& dev, char delim);
63 
68  void close();
69 
74  bool opened() const;
75 
82  std::string read();
83 
91  void write(const std::string& msg);
92 
93 private:
95  int fd = -1;
101  std::unique_ptr<char[]> buf = std::make_unique<char[]>(4097);
102 };
103 
104 } // namespace RV2AJ
105 } // namespace Kinematics
106 } // namespace HLR
107 
108 #endif // KINEMATICS_RV2AJ_DRIVER_SERIAL_HPP
std::string read()
Reads message from open serial device up to (including) delimiter.
Serial()=default
Constructor.
OO wrapper around POSIX serial devices.
Definition: Serial.hpp:14
void write(const std::string &msg)
Writes message to open serial device.
void open(const std::string &dev, char delim)
Open specified serial device.
bool opened() const
Returns whether serial device is open.
virtual ~Serial()
Destructor.
void close()
Closes active serial device.
Serial & operator=(const Serial &s)=delete
Copy assignment operator, deleted.