6 // Written by Curtis Olson, started November 1999.
8 // Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // 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.
27 #ifndef _SG_SERIAL_HXX
28 #define _SG_SERIAL_HXX
32 # error This library requires C++
35 #include <simgear/compiler.h>
39 #include <simgear/serial/serial.hxx>
41 #include "iochannel.hxx"
46 * A serial I/O class based on SGIOChannel.
48 class SGSerial : public SGIOChannel {
54 char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ];
60 * Create an instance of SGSerial.
61 * This creates an instance of the SGSerial class. You need to
62 * provide the serial device name and desired baud rate. For Unix
63 * style systems, device names will be similar to
64 * ``/dev/ttyS0''. For DOS style systems you may want to use
65 * something similar to ``COM1:''. As with the SGFile class,
66 * device is not opened immediately, but instead will be opened
67 * when the open() method is called.
68 * @param device_name name of serial device
69 * @param baud_rate speed of communication
71 SGSerial( const string& device_name, const string& baud_rate );
76 // open the serial port based on specified direction
77 bool open( const SGProtocolDir d );
79 // read a block of data of specified size
80 int read( char *buf, int length );
82 // read a line of data, length is max size of input buffer
83 int readline( char *buf, int length );
86 int write( const char *buf, const int length );
88 // write null terminated string to port
89 int writestring( const char *str );
94 /** @return the serial port device name */
95 inline string get_device() const { return device; }
97 /** @return the baud rate */
98 inline string get_baud() const { return baud; }
102 #endif // _SG_SERIAL_HXX