00001 /*************************************************************************** 00002 LOW_portSerial.h - description 00003 ------------------- 00004 begin : Mon Jul 29 2002 00005 copyright : (C) 2002 by Harald Roelle 00006 email : roelle@informatik.uni-muenchen.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef LOW_PORTSERIAL_H 00019 #define LOW_PORTSERIAL_H 00020 00021 00022 #include "LOW_types.h" 00023 #include "LOW_exception.h" 00024 00025 00026 /** Abstract base class for serial ports. 00027 Each instance represents one serial port. 00028 00029 Specific platforms dereive their implementation classes from this class. 00030 00031 The instances are created by LOW_portSerialFactory, following the factory 00032 design pattern. 00033 00034 <B>Note:</B> There is no prescribed constructor. A class deriving from this 00035 one should have a constructor which only requires to specify the 00036 port, but no extra setup parameters for it.<BR> 00037 This enables parts of your software to specify a serial port by 00038 creating an object, but without knowing the specific setup for it. 00039 This setup might be known then by other parts, which receive the 00040 object as port specification. 00041 00042 This class is thread-safe. 00043 00044 @see LOW_portSerialFactory 00045 00046 @author Harald Roelle 00047 */ 00048 class LOW_portSerial { 00049 00050 //======================================================================================= 00051 public: 00052 00053 //===================================================================================== 00054 // 00055 // exceptions 00056 // 00057 00058 /** Exception base class for all exceptions thrown by LOW_portSerial. */ 00059 class_DERIVE_FROM_EXCEPTION( portSerial_error, LOW_exception); 00060 00061 00062 //===================================================================================== 00063 // 00064 // constants 00065 // 00066 00067 static const unsigned int defaultTimeout = 5; 00068 00069 00070 //===================================================================================== 00071 // 00072 // type definitions 00073 // 00074 00075 /** Serial flow control type. */ 00076 typedef enum { none_flowControl, xonxoff_flowControl, rtscts_flowControl} flowControl_t; 00077 00078 /** Number of data bits type. */ 00079 typedef enum { bit5_size, bit6_size, bit7_size, bit8_size} dataBitsSite_t; 00080 00081 /** Parity control type. */ 00082 typedef enum { no_parity, odd_parity, even_parity} parity_t; 00083 00084 /** Number of stop bits type. */ 00085 typedef enum { bit1_stopBit, bit2_stopBit} stopBits_t; 00086 00087 /** Serial speed control type */ 00088 typedef enum { B50_speed, B75_speed, B110_speed, B134_speed, B150_speed, B200_speed, 00089 B300_speed, B600_speed, B1200_speed, B1800_speed, B2400_speed, B4800_speed, 00090 B9600_speed, B19200_speed, B38400_speed, B57600_speed, B115200_speed, 00091 B10472_speed} speed_t; 00092 00093 00094 //===================================================================================== 00095 // 00096 // constructors 00097 // 00098 00099 /** Destructor. 00100 */ 00101 virtual ~LOW_portSerial(); 00102 00103 00104 //===================================================================================== 00105 // 00106 // methods 00107 // 00108 00109 /** Configure the serial port. 00110 Abstract method to be implemented by derived class. 00111 00112 @param inFlowCtl Flow control. 00113 @param inDataBits Number of data bits. 00114 @param inParity Parity control. 00115 @param inStopBits Number of stop bits. 00116 @param inSpeed Port speed. 00117 */ 00118 virtual void tty_configure( const flowControl_t inFlowCtl, const dataBitsSite_t inDataBits, 00119 const parity_t inParity, const stopBits_t inStopBits, const speed_t inSpeed) = 0; 00120 00121 00122 /** Flushs serial input and/or output buffers. 00123 Abstract method to be implemented by derived class. 00124 00125 @param inFlushIn If set to true input buffer is flushed. 00126 @param inFlushOut If set to true output buffer is flushed. 00127 */ 00128 virtual void tty_flush( const bool inFlushIn = true, const bool inFlushOut = true) = 0; 00129 00130 00131 /** Sends break signal. 00132 Abstract method to be implemented by derived class. 00133 */ 00134 virtual void tty_break() = 0; 00135 00136 00137 /** Reads on byte from serial port. 00138 Abstract method to be implemented by derived class. 00139 00140 @param inTrashExtraReply If true one extra byte is read from serial port and trashed. 00141 @param inSecTimeout Timeout in seconds. 00142 @return Byte read from serial port. 00143 */ 00144 virtual uint8_t tty_readByte( const bool inTrashExtraReply = false, const unsigned int inSecTimeout = defaultTimeout) = 0; 00145 00146 00147 /** Reads multiple bytes from serial port. 00148 The desired number of bytes to read is specified by the preset length 00149 of the vector parameter. 00150 00151 Abstract method to be implemented by derived class. 00152 00153 @param outReadBytes Reference to byte vector, where read bytes are stored in. 00154 @param inTrashExtraReply If true one extra byte is read from serial port at the end 00155 and trashed. 00156 @param inSecTimeout Timeout in seconds. 00157 */ 00158 virtual void tty_read( byteVec_t &outReadBytes, const bool inTrashExtraReply = false, const unsigned int inSecTimeout = defaultTimeout) = 0; 00159 00160 00161 /** Writes one byte to serial port. 00162 Abstract method to be implemented by derived class. 00163 00164 @param inWriteByte Byte to write. 00165 */ 00166 virtual void tty_write( const uint8_t inWriteByte) = 0; 00167 00168 00169 /** Writes multiple bytes to serial port. 00170 The desired number of bytes to write is specified by the preset length 00171 of the vector parameter. 00172 00173 Abstract method to be implemented by derived class. 00174 00175 @param inWriteBytes Reference to byte vector which contains bytes to write. 00176 */ 00177 virtual void tty_write( const byteVec_t &inWriteBytes) = 0; 00178 00179 }; 00180 00181 #endif