serial  1.2.1
Cross-platform, serial port library written in C++
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 
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 
66  void
67  open ();
68 
69  void
70  close ();
71 
72  bool
73  isOpen () const;
74 
75  size_t
76  available ();
77 
78  bool
79  waitReadable (uint32_t timeout);
80 
81  void
82  waitByteTimes (size_t count);
83 
84  size_t
85  read (uint8_t *buf, size_t size = 1);
86 
87  size_t
88  write (const uint8_t *data, size_t length);
89 
90  void
91  flush ();
92 
93  void
94  flushInput ();
95 
96  void
97  flushOutput ();
98 
99  void
100  sendBreak (int duration);
101 
102  void
103  setBreak (bool level);
104 
105  void
106  setRTS (bool level);
107 
108  void
109  setDTR (bool level);
110 
111  bool
112  waitForChange ();
113 
114  bool
115  getCTS ();
116 
117  bool
118  getDSR ();
119 
120  bool
121  getRI ();
122 
123  bool
124  getCD ();
125 
126  void
127  setPort (const string &port);
128 
129  string
130  getPort () const;
131 
132  void
133  setTimeout (Timeout &timeout);
134 
135  Timeout
136  getTimeout () const;
137 
138  void
139  setBaudrate (unsigned long baudrate);
140 
141  unsigned long
142  getBaudrate () const;
143 
144  void
145  setBytesize (bytesize_t bytesize);
146 
147  bytesize_t
148  getBytesize () const;
149 
150  void
151  setParity (parity_t parity);
152 
153  parity_t
154  getParity () const;
155 
156  void
157  setStopbits (stopbits_t stopbits);
158 
159  stopbits_t
160  getStopbits () const;
161 
162  void
163  setFlowcontrol (flowcontrol_t flowcontrol);
164 
166  getFlowcontrol () const;
167 
168  void
169  readLock ();
170 
171  void
172  readUnlock ();
173 
174  void
175  writeLock ();
176 
177  void
178  writeUnlock ();
179 
180 protected:
181  void reconfigurePort ();
182 
183 private:
184  wstring port_; // Path to the file descriptor
185  HANDLE fd_;
186 
187  bool is_open_;
188 
189  Timeout timeout_; // Timeout for read operations
190  unsigned long baudrate_; // Baudrate
191 
192  parity_t parity_; // Parity
193  bytesize_t bytesize_; // Size of the bytes
194  stopbits_t stopbits_; // Stop Bits
195  flowcontrol_t flowcontrol_; // Flow Control
196 
197  // Mutex used to lock the read functions
198  HANDLE read_mutex;
199  // Mutex used to lock the write functions
200  HANDLE write_mutex;
201 };
202 
203 }
204 
205 #endif // SERIAL_IMPL_WINDOWS_H
206 
207 #endif // if defined(_WIN32)
parity_t getParity() const
Definition: serial.cc:323
void setBaudrate(uint32_t baudrate)
Definition: serial.cc:293
bytesize_t getBytesize() const
Definition: serial.cc:311
void close()
Definition: serial.cc:87
size_t write(const uint8_t *data, size_t size)
Definition: serial.cc:252
void sendBreak(int duration)
Definition: serial.cc:371
parity_t
Definition: serial.h:66
std::string getPort() const
Definition: serial.cc:276
void open()
Definition: serial.cc:81
flowcontrol_t getFlowcontrol() const
Definition: serial.cc:347
bytesize_t
Definition: serial.h:56
void flushOutput()
Definition: serial.cc:365
void setDTR(bool level=true)
Definition: serial.cc:386
Definition: unix.h:47
bool getDSR()
Definition: serial.cc:401
bool getCTS()
Definition: serial.cc:396
void setTimeout(Timeout &timeout)
Definition: serial.cc:282
void flush()
Definition: serial.cc:352
void flushInput()
Definition: serial.cc:359
Definition: serial.h:690
void setBreak(bool level=true)
Definition: serial.cc:376
bool waitForChange()
Definition: serial.cc:391
stopbits_t getStopbits() const
Definition: serial.cc:335
bool getCD()
Definition: serial.cc:411
bool isOpen() const
Definition: serial.cc:93
void setRTS(bool level=true)
Definition: serial.cc:381
void setBytesize(bytesize_t bytesize)
Definition: serial.cc:305
void setPort(const std::string &port)
Definition: serial.cc:265
Timeout getTimeout() const
Definition: serial.cc:288
bool waitReadable()
Definition: serial.cc:105
Definition: serial.h:672
bool getRI()
Definition: serial.cc:406
void setStopbits(stopbits_t stopbits)
Definition: serial.cc:329
stopbits_t
Definition: serial.h:77
void setFlowcontrol(flowcontrol_t flowcontrol)
Definition: serial.cc:341
size_t read(uint8_t *buffer, size_t size)
Definition: serial.cc:124
uint32_t getBaudrate() const
Definition: serial.cc:299
size_t available()
Definition: serial.cc:99
void setParity(parity_t parity)
Definition: serial.cc:317
void waitByteTimes(size_t count)
Definition: serial.cc:112
flowcontrol_t
Definition: serial.h:86