win.h
Go to the documentation of this file.
1 
37 #if defined(_WIN32)
38 
39 #ifndef SERIAL_IMPL_WINDOWS_H
40 #define SERIAL_IMPL_WINDOWS_H
41 
42 #include "serial/serial.h"
43 
44 #include "windows.h"
45 
46 namespace serial {
47 
48  using std::string;
49  using std::wstring;
50  using std::invalid_argument;
51 
53  using serial::IOException;
54 
55  class serial::Serial::SerialImpl {
56  public:
57  SerialImpl(const string &port,
58  unsigned long baudrate,
59  bytesize_t bytesize,
60  parity_t parity,
61  stopbits_t stopbits,
62  flowcontrol_t flowcontrol);
63 
64  virtual ~SerialImpl();
65  void open();
66  void close();
67  bool isOpen() const;
68  size_t available();
69  bool waitReadable(uint32_t timeout);
70  void waitByteTimes(size_t count);
71  size_t read(uint8_t *buf, size_t size = 1);
72  size_t write(const uint8_t *data, size_t length);
73  void flush();
74  void flushInput();
75  void flushOutput();
76  void sendBreak(int duration);
77  void setBreak(bool level);
78  void setRTS(bool level);
79  void setDTR(bool level);
80  bool waitForChange();
81  bool getCTS();
82  bool getDSR();
83  bool getRI();
84  bool getCD();
85  void setPort(const string &port);
86  string getPort() const;
87  void setTimeout(Timeout &timeout);
88  Timeout getTimeout() const;
89  void setBaudrate(unsigned long baudrate);
90  unsigned long getBaudrate() const;
91  void setBytesize(bytesize_t bytesize);
92  bytesize_t getBytesize() const;
93  void setParity(parity_t parity);
94  parity_t getParity() const;
95  void setStopbits(stopbits_t stopbits);
96  stopbits_t getStopbits() const;
97  void setFlowcontrol(flowcontrol_t flowcontrol);
99  void readLock();
100  void readUnlock();
101  void writeLock();
102  void writeUnlock();
103 
104  protected:
105  void reconfigurePort();
106 
107  private:
108  string port;
109  wstring port_; // Path to the file descriptor
110  HANDLE fd_;
111 
112  bool is_open_;
113 
114  Timeout timeout_; // Timeout for read operations
115  unsigned long baudrate_; // Baudrate
116 
117  parity_t parity_; // Parity
118  bytesize_t bytesize_; // Size of the bytes
119  stopbits_t stopbits_; // Stop Bits
120  flowcontrol_t flowcontrol_; // Flow Control
121 
122  // Mutex used to lock the read functions
123  HANDLE read_mutex;
124  // Mutex used to lock the write functions
125  HANDLE write_mutex;
126  };
127 
128 }
129 
130 #endif // SERIAL_IMPL_WINDOWS_H
131 
132 #endif // if defined(_WIN32)
size_t available()
Definition: serial.cc:99
void sendBreak(int duration)
Definition: serial.cc:371
void close()
Definition: serial.cc:87
flowcontrol_t getFlowcontrol() const
Definition: serial.cc:347
void flushInput()
Definition: serial.cc:359
void waitByteTimes(size_t count)
Definition: serial.cc:112
bool getCD()
Definition: serial.cc:411
void setTimeout(Timeout &timeout)
Definition: serial.cc:282
bytesize_t getBytesize() const
Definition: serial.cc:311
void setBaudrate(uint32_t baudrate)
Definition: serial.cc:293
void setBreak(bool level=true)
Definition: serial.cc:376
parity_t
Definition: serial.h:66
stopbits_t getStopbits() const
Definition: serial.cc:335
bool waitReadable()
Definition: serial.cc:105
bytesize_t
Definition: serial.h:56
void setRTS(bool level=true)
Definition: serial.cc:381
bool getRI()
Definition: serial.cc:406
void flush()
Definition: serial.cc:352
void setStopbits(stopbits_t stopbits)
Definition: serial.cc:329
Definition: unix.h:47
void setBytesize(bytesize_t bytesize)
Definition: serial.cc:305
void open()
Definition: serial.cc:81
bool isOpen() const
Definition: serial.cc:93
bool getCTS()
Definition: serial.cc:396
bool getDSR()
Definition: serial.cc:401
void setPort(const std::string &port)
Definition: serial.cc:265
size_t read(uint8_t *buffer, size_t size)
Definition: serial.cc:124
void flushOutput()
Definition: serial.cc:365
uint32_t getBaudrate() const
Definition: serial.cc:299
stopbits_t
Definition: serial.h:77
std::string getPort() const
Definition: serial.cc:276
void setDTR(bool level=true)
Definition: serial.cc:386
Timeout getTimeout() const
Definition: serial.cc:288
bool waitForChange()
Definition: serial.cc:391
void setParity(parity_t parity)
Definition: serial.cc:317
parity_t getParity() const
Definition: serial.cc:323
size_t write(const uint8_t *data, size_t size)
Definition: serial.cc:252
void setFlowcontrol(flowcontrol_t flowcontrol)
Definition: serial.cc:341
flowcontrol_t
Definition: serial.h:86


xarm_api
Author(s):
autogenerated on Sat May 8 2021 02:51:23