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 
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)
void setBytesize(bytesize_t bytesize)
Definition: unix.cc:736
pthread_mutex_t read_mutex
Definition: unix.h:212
void waitByteTimes(size_t count)
Definition: unix.cc:526
void setRTS(bool level)
Definition: unix.cc:852
string getPort() const
Definition: unix.cc:704
void setStopbits(stopbits_t stopbits)
Definition: unix.cc:764
Timeout getTimeout() const
Definition: unix.cc:716
void setBaudrate(unsigned long baudrate)
Definition: unix.cc:722
bytesize_t bytesize_
Definition: unix.h:207
parity_t
Definition: serial.h:66
size_t read(uint8_t *buf, size_t size=1)
Definition: unix.cc:533
bytesize_t
Definition: serial.h:56
stopbits_t getStopbits() const
Definition: unix.cc:772
pthread_mutex_t write_mutex
Definition: unix.h:214
flowcontrol_t flowcontrol_
Definition: unix.h:209
void setDTR(bool level)
Definition: unix.cc:878
Definition: unix.h:47
stopbits_t stopbits_
Definition: unix.h:208
unsigned long baudrate_
Definition: unix.h:203
parity_t getParity() const
Definition: unix.cc:758
bytesize_t getBytesize() const
Definition: unix.cc:744
bool waitReadable(uint32_t timeout)
Definition: unix.cc:495
bool isOpen() const
Definition: unix.cc:475
SerialImpl(const string &port, unsigned long baudrate, bytesize_t bytesize, parity_t parity, stopbits_t stopbits, flowcontrol_t flowcontrol)
Definition: unix.cc:108
void setParity(parity_t parity)
Definition: unix.cc:750
void sendBreak(int duration)
Definition: unix.cc:819
unsigned long getBaudrate() const
Definition: unix.cc:730
stopbits_t
Definition: serial.h:77
void setFlowcontrol(flowcontrol_t flowcontrol)
Definition: unix.cc:778
void setTimeout(Timeout &timeout)
Definition: unix.cc:710
flowcontrol_t getFlowcontrol() const
Definition: unix.cc:786
size_t write(const uint8_t *data, size_t length)
Definition: unix.cc:610
void setPort(const string &port)
Definition: unix.cc:698
void setBreak(bool level)
Definition: unix.cc:828
flowcontrol_t
Definition: serial.h:86


serial
Author(s): William Woodall , John Harrison
autogenerated on Thu Jan 9 2020 07:18:58