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., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #ifndef _SG_SERIAL_HXX
28 #define _SG_SERIAL_HXX
32 # error This library requires C++
35 #include <simgear/compiler.h>
39 // #ifdef SG_HAVE_STD_INCLUDES
45 #include <simgear/serial/serial.hxx>
47 #include "iochannel.hxx"
52 * A serial I/O class based on SGIOChannel.
54 class SGSerial : public SGIOChannel {
60 char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ];
66 * Create an instance of SGSerial.
67 * This creates an instance of the SGSerial class. You need to
68 * provide the serial device name and desired baud rate. For Unix
69 * style systems, device names will be similar to
70 * ``/dev/ttyS0''. For DOS style systems you may want to use
71 * something similar to ``COM1:''. As with the SGFile class,
72 * device is not opened immediately, but instead will be opened
73 * when the open() method is called.
74 * @param device_name name of serial device
75 * @param baud_rate speed of communication
77 SGSerial( const string& device_name, const string& baud_rate );
82 // open the serial port based on specified direction
83 bool open( const SGProtocolDir d );
85 // read a block of data of specified size
86 int read( char *buf, int length );
88 // read a line of data, length is max size of input buffer
89 int readline( char *buf, int length );
92 int write( const char *buf, const int length );
94 // write null terminated string to port
95 int writestring( const char *str );
100 /** @return the serial port device name */
101 inline string get_device() const { return device; }
103 /** @return the baud rate */
104 inline string get_baud() const { return baud; }
108 #endif // _SG_SERIAL_HXX