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 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++
36 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
40 #include <simgear/compiler.h>
44 // if someone know how to do this all with C++ streams let me know
49 * A class to encapsulate low level serial port IO.
53 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
54 typedef HANDLE fd_type;
66 /** Default constructor */
71 * @param device device name
72 * @param baud baud rate
74 SGSerialPort(const string& device, int baud);
79 /** Open a the serial port
80 * @param device name of device
81 * @return success/failure
83 bool open_port(const string& device);
85 /** Close the serial port
86 * @return success/failure
91 * @param baud baud rate
92 * @return success/failure
94 bool set_baud(int baud);
96 /** Read from the serial port
97 * @return line of data
101 /** Read from the serial port
102 * @param buf input buffer
103 * @param len length of buffer (i.e. max number of bytes to read
104 * @return number of bytes read
106 int read_port(char *buf, int len);
108 /** Write to the serial port
109 * @param value output string
110 * @return number of bytes written
112 int write_port(const string& value);
114 /** Write to the serial port
115 * @param buf pointer to character buffer containing output data
116 * @param len number of bytes to write from the buffer
117 * @return number of bytes written
119 int write_port(const char *buf, int len);
121 /** @return true if device open */
122 inline bool is_enabled() { return dev_open; }
126 #endif // _SERIAL_HXX