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)
serial::parity_t
parity_t
Definition: serial.h:66
serial::Serial::SerialImpl::close
void close()
Definition: unix.cc:455
serial::Serial::SerialImpl::waitReadable
bool waitReadable(uint32_t timeout)
Definition: unix.cc:492
serial
Definition: unix.h:47
serial::Serial::SerialImpl::sendBreak
void sendBreak(int duration)
Definition: unix.cc:811
serial::Serial::SerialImpl::getPort
string getPort() const
Definition: unix.cc:696
serial::Serial::SerialImpl::getCTS
bool getCTS()
Definition: unix.cc:939
serial::Serial::SerialImpl::SerialImpl
SerialImpl(const string &port, unsigned long baudrate, bytesize_t bytesize, parity_t parity, stopbits_t stopbits, flowcontrol_t flowcontrol)
Definition: unix.cc:108
serial::Serial::SerialImpl::flushInput
void flushInput()
Definition: unix.cc:793
serial::Serial::SerialImpl::flush
void flush()
Definition: unix.cc:784
serial::Serial::SerialImpl::fd_
int fd_
Definition: unix.h:196
serial::Serial::SerialImpl::getParity
parity_t getParity() const
Definition: unix.cc:750
serial::Serial::SerialImpl::getStopbits
stopbits_t getStopbits() const
Definition: unix.cc:764
serial::Serial::SerialImpl::writeLock
void writeLock()
Definition: unix.cc:1041
serial::Serial::SerialImpl::parity_
parity_t parity_
Definition: unix.h:206
serial::Serial::SerialImpl::setTimeout
void setTimeout(Timeout &timeout)
Definition: unix.cc:702
serial::Serial::SerialImpl::timeout_
Timeout timeout_
Definition: unix.h:202
serial::Serial::SerialImpl::available
size_t available()
Definition: unix.cc:478
serial::Serial::SerialImpl::setBreak
void setBreak(bool level)
Definition: unix.cc:820
serial::Serial::SerialImpl::getRI
bool getRI()
Definition: unix.cc:981
serial::Serial::SerialImpl::~SerialImpl
virtual ~SerialImpl()
Definition: unix.cc:122
serial::Serial::SerialImpl::setParity
void setParity(parity_t parity)
Definition: unix.cc:742
serial::IOException
Definition: serial.h:688
serial::Serial::SerialImpl::write
size_t write(const uint8_t *data, size_t length)
Definition: unix.cc:607
serial::Serial::SerialImpl::getFlowcontrol
flowcontrol_t getFlowcontrol() const
Definition: unix.cc:778
serial::Serial::SerialImpl::setFlowcontrol
void setFlowcontrol(flowcontrol_t flowcontrol)
Definition: unix.cc:770
serial::bytesize_t
bytesize_t
Definition: serial.h:56
serial::Serial::SerialImpl::waitByteTimes
void waitByteTimes(size_t count)
Definition: unix.cc:523
serial::Serial::SerialImpl::setPort
void setPort(const string &port)
Definition: unix.cc:690
python_serial_test.timeout
timeout
Definition: python_serial_test.py:10
serial::Serial::SerialImpl::getCD
bool getCD()
Definition: unix.cc:1002
serial::Serial::SerialImpl::readLock
void readLock()
Definition: unix.cc:1023
serial::Serial::SerialImpl::setStopbits
void setStopbits(stopbits_t stopbits)
Definition: unix.cc:756
serial::Serial::SerialImpl::setBaudrate
void setBaudrate(unsigned long baudrate)
Definition: unix.cc:714
serial::Serial::SerialImpl
Definition: unix.h:66
serial::Serial::SerialImpl::getDSR
bool getDSR()
Definition: unix.cc:960
serial::Serial::SerialImpl::readUnlock
void readUnlock()
Definition: unix.cc:1032
serial::Serial::SerialImpl::reconfigurePort
void reconfigurePort()
Definition: unix.cc:160
serial::Serial::SerialImpl::open
void open()
Definition: unix.cc:130
serial.h
serial::Serial::SerialImpl::writeUnlock
void writeUnlock()
Definition: unix.cc:1050
serial::Serial::SerialImpl::flushOutput
void flushOutput()
Definition: unix.cc:802
serial::Serial::SerialImpl::setBytesize
void setBytesize(bytesize_t bytesize)
Definition: unix.cc:728
serial::Serial::SerialImpl::is_open_
bool is_open_
Definition: unix.h:198
serial::Serial::SerialImpl::read_mutex
pthread_mutex_t read_mutex
Definition: unix.h:212
serial::Serial::SerialImpl::bytesize_
bytesize_t bytesize_
Definition: unix.h:207
serial::flowcontrol_t
flowcontrol_t
Definition: serial.h:86
serial::Serial::SerialImpl::read
size_t read(uint8_t *buf, size_t size=1)
Definition: unix.cc:530
serial::stopbits_t
stopbits_t
Definition: serial.h:77
serial::Serial::SerialImpl::setRTS
void setRTS(bool level)
Definition: unix.cc:844
serial::Serial::SerialImpl::write_mutex
pthread_mutex_t write_mutex
Definition: unix.h:214
serial::Serial::SerialImpl::flowcontrol_
flowcontrol_t flowcontrol_
Definition: unix.h:209
serial::Serial::SerialImpl::isOpen
bool isOpen() const
Definition: unix.cc:472
serial::Serial::SerialImpl::getTimeout
Timeout getTimeout() const
Definition: unix.cc:708
serial::Serial::SerialImpl::port_
string port_
Definition: unix.h:195
serial::Serial::SerialImpl::setDTR
void setDTR(bool level)
Definition: unix.cc:870
serial::Serial::SerialImpl::stopbits_
stopbits_t stopbits_
Definition: unix.h:208
serial::SerialException
Definition: serial.h:670
serial::Serial::SerialImpl::waitForChange
bool waitForChange()
Definition: unix.cc:896
serial::Serial::SerialImpl::getBytesize
bytesize_t getBytesize() const
Definition: unix.cc:736
serial::Serial::SerialImpl::getBaudrate
unsigned long getBaudrate() const
Definition: unix.cc:722
serial::Serial::SerialImpl::baudrate_
unsigned long baudrate_
Definition: unix.h:203


ubiquity_motor
Author(s):
autogenerated on Thu Nov 16 2023 03:30:56