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 - curt@flightgear.org
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 Library General Public
21 // License along with this library; if not, write to the
22 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 // Boston, MA 02111-1307, USA.
33 # error This library requires C++
40 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
44 #include <simgear/compiler.h>
48 // if someone know how to do this all with C++ streams let me know
53 * A class to encapsulate low level serial port IO.
57 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
58 typedef HANDLE fd_type;
70 /** Default constructor */
75 * @param device device name
76 * @param baud baud rate
78 FGSerialPort(const string& device, int baud);
83 /** Open a the serial port
84 * @param device name of device
85 * @return success/failure
87 bool open_port(const string& device);
89 /** Close the serial port
90 * @return success/failure
95 * @param baud baud rate
96 * @return success/failure
98 bool set_baud(int baud);
100 /** Read from the serial port
101 * @return line of data
105 /** Read from the serial port
106 * @param buf input buffer
107 * @param len length of buffer (i.e. max number of bytes to read
108 * @return number of bytes read
110 int read_port(char *buf, int len);
112 /** Write to the serial port
113 * @param value output string
114 * @return number of bytes written
116 int write_port(const string& value);
118 /** Write to the serial port
119 * @param buf pointer to character buffer containing output data
120 * @param len number of bytes to write from the buffer
121 * @return number of bytes written
123 int write_port(const char *buf, int len);
125 /** @return true if device open */
126 inline bool is_enabled() { return dev_open; }
130 #endif // _SERIAL_HXX