Adding initial windows support.
[serial.git] / include / serial / impl / win.h
1 /*!
2  * \file serial/impl/windows.h
3  * \author  William Woodall <wjwwood@gmail.com>
4  * \author  John Harrison <ash@greaterthaninfinity.com>
5  * \version 0.1
6  *
7  * \section LICENSE
8  *
9  * The MIT License
10  *
11  * Copyright (c) 2012 William Woodall, John Harrison
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a 
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included in
21  * all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
29  * DEALINGS IN THE SOFTWARE.
30  *
31  * \section DESCRIPTION
32  *
33  * This provides a windows implementation of the Serial class interface.
34  *
35  */
36
37 #ifndef SERIAL_IMPL_WINDOWS_H
38 #define SERIAL_IMPL_WINDOWS_H
39
40 #include "serial/serial.h"
41
42 #include "windows.h"
43
44 namespace serial {
45
46 using std::string;
47 using std::invalid_argument;
48
49 using serial::SerialExecption;
50 using serial::IOException;
51
52 class serial::Serial::SerialImpl {
53 public:
54   SerialImpl (const string &port,
55               unsigned long baudrate,
56               bytesize_t bytesize,
57               parity_t parity,
58               stopbits_t stopbits,
59               flowcontrol_t flowcontrol);
60
61   virtual ~SerialImpl ();
62
63   void
64   open ();
65
66   void
67   close ();
68
69   bool
70   isOpen () const;
71
72   size_t
73   available ();
74
75   size_t
76   read (uint8_t *buf, size_t size = 1);
77
78   size_t
79   write (const uint8_t *data, size_t length);
80
81   void
82   flush ();
83
84   void
85   flushInput ();
86
87   void
88   flushOutput ();
89
90   void
91   sendBreak (int duration);
92
93   void
94   setBreak (bool level);
95
96   void
97   setRTS (bool level);
98
99   void
100   setDTR (bool level);
101
102   bool
103   waitForChange ();
104
105   bool
106   getCTS ();
107
108   bool
109   getDSR ();
110
111   bool
112   getRI ();
113
114   bool
115   getCD ();
116
117   void
118   setPort (const string &port);
119
120   string
121   getPort () const;
122
123   void
124   setTimeout (Timeout &timeout);
125
126   Timeout
127   getTimeout () const;
128
129   void
130   setBaudrate (unsigned long baudrate);
131
132   unsigned long
133   getBaudrate () const;
134
135   void
136   setBytesize (bytesize_t bytesize);
137
138   bytesize_t
139   getBytesize () const;
140
141   void
142   setParity (parity_t parity);
143
144   parity_t
145   getParity () const;
146
147   void
148   setStopbits (stopbits_t stopbits);
149
150   stopbits_t
151   getStopbits () const;
152
153   void
154   setFlowcontrol (flowcontrol_t flowcontrol);
155
156   flowcontrol_t
157   getFlowcontrol () const;
158
159   void
160   readLock ();
161
162   void
163   readUnlock ();
164
165   void
166   writeLock ();
167
168   void
169   writeUnlock ();
170
171 protected:
172   void reconfigurePort ();
173
174 private:
175   string port_;               // Path to the file descriptor
176   HANDLE fd_;
177
178   bool is_open_;
179
180   Timeout timeout_;           // Timeout for read operations
181   unsigned long baudrate_;    // Baudrate
182
183   parity_t parity_;           // Parity
184   bytesize_t bytesize_;       // Size of the bytes
185   stopbits_t stopbits_;       // Stop Bits
186   flowcontrol_t flowcontrol_; // Flow Control
187
188   // Mutex used to lock the read functions
189   HANDLE read_mutex;
190   // Mutex used to lock the write functions
191   HANDLE write_mutex;
192 };
193
194 }
195
196 #endif // SERIAL_IMPL_WINDOWS_H
This page took 0.03642 seconds and 4 git commands to generate.