3 * Low level serial I/O support (for unix/cygwin and windows)
6 // Written by Curtis Olson, started November 1998.
8 // Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Library General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 # error This library requires C++
39 #include <simgear/compiler.h>
43 // if someone know how to do this all with C++ streams let me know
48 * A class to encapsulate low level serial port IO.
53 typedef HANDLE fd_type;
65 /** Default constructor */
70 * @param device device name
71 * @param baud baud rate
73 SGSerialPort(const string& device, int baud);
78 /** Open a the serial port
79 * @param device name of device
80 * @return success/failure
82 bool open_port(const string& device);
84 /** Close the serial port
85 * @return success/failure
90 * @param baud baud rate
91 * @return success/failure
93 bool set_baud(int baud);
95 /** Read from the serial port
96 * @return line of data
100 /** Read from the serial port
101 * @param buf input buffer
102 * @param len length of buffer (i.e. max number of bytes to read
103 * @return number of bytes read
105 int read_port(char *buf, int len);
107 /** Write to the serial port
108 * @param value output string
109 * @return number of bytes written
111 int write_port(const string& value);
113 /** Write to the serial port
114 * @param buf pointer to character buffer containing output data
115 * @param len number of bytes to write from the buffer
116 * @return number of bytes written
118 int write_port(const char *buf, int len);
120 /** @return true if device open */
121 inline bool is_enabled() { return dev_open; }
125 #endif // _SERIAL_HXX