00001 /*************************************************************************** 00002 LOW_portSerial.h - description 00003 ------------------- 00004 begin : Mon Jul 29 2002 00005 copyright : (C) 2002 by Harald Roelle, Helmut Reiser 00006 email : roelle@informatik.uni-muenchen.de, reiser@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 @see LOW_portSerialFactory 00043 00044 @author Harald Roelle, Helmut Reiser 00045 */ 00046 class LOW_portSerial { 00047 00048 //======================================================================================= 00049 public: 00050 00051 //===================================================================================== 00052 // 00053 // exceptions 00054 // 00055 00056 /** Exception base class for all exceptions thrown by LOW_portSerial. */ 00057 class_DERIVE_FROM_EXCEPTION( portSerial_error, LOW_exception); 00058 00059 00060 //===================================================================================== 00061 // 00062 // data types 00063 // 00064 00065 /** Serial flow control type. */ 00066 typedef enum { none_flowControl, xonxoff_flowControl, rtscts_flowControl} flowControl_t; 00067 00068 /** Number of data bits type. */ 00069 typedef enum { bit5_size, bit6_size, bit7_size, bit8_size} dataBitsSite_t; 00070 00071 /** Parity control type. */ 00072 typedef enum { no_parity, odd_parity, even_parity} parity_t; 00073 00074 /** Number of stop bits type. */ 00075 typedef enum { bit1_stopBit, bit2_stopBit} stopBits_t; 00076 00077 /** Serial speed control type */ 00078 typedef enum { B50_speed, B75_speed, B110_speed, B134_speed, B150_speed, B200_speed, 00079 B300_speed, B600_speed, B1200_speed, B1800_speed, B2400_speed, B4800_speed, 00080 B9600_speed, B19200_speed, B38400_speed, B57600_speed, B115200_speed, 00081 B10472_speed} speed_t; 00082 00083 00084 //===================================================================================== 00085 // 00086 // methods 00087 // 00088 00089 /** Configure the serial port. 00090 Abstract method to be implemented by derived class. 00091 00092 @param inFlowCtl Flow control. 00093 @param inDataBits Number of data bits. 00094 @param inParity Parity control. 00095 @param inStopBits Number of stop bits. 00096 @param inSpeed Port speed. 00097 */ 00098 virtual void tty_configure( const flowControl_t inFlowCtl, const dataBitsSite_t inDataBits, 00099 const parity_t inParity, const stopBits_t inStopBits, const speed_t inSpeed) const = 0; 00100 00101 /** Flushs serial input and/or output buffers. 00102 Abstract method to be implemented by derived class. 00103 00104 @param inFlushIn If set to true input buffer is flushed. 00105 @param inFlushOut If set to true output buffer is flushed. 00106 */ 00107 virtual void tty_flush( const bool inFlushIn = true, const bool inFlushOut = true) const = 0; 00108 00109 /** Sends break signal. 00110 Abstract method to be implemented by derived class. 00111 */ 00112 virtual void tty_break() const = 0; 00113 00114 /** Reads on byte from serial port. 00115 Abstract method to be implemented by derived class. 00116 00117 @param inTrashExtraReply If true one extra byte is read from serial port and trashed. 00118 @return Byte read from serial port. 00119 */ 00120 virtual uint8_t tty_readByte( const bool inTrashExtraReply = false) const = 0; 00121 00122 /** Reads multiple bytes from serial port. 00123 The desired number of bytes to read is specified by the preset length 00124 of the vector parameter. 00125 00126 Abstract method to be implemented by derived class. 00127 00128 @param outReadBytes Reference to byte vector, where read bytes are stored in. 00129 @param inTrashExtraReply If true one extra byte is read from serial port at the end 00130 and trashed. 00131 */ 00132 virtual void tty_read( byteVec_t &outReadBytes, const bool inTrashExtraReply = false) const = 0; 00133 00134 /** Writes one byte to serial port. 00135 Abstract method to be implemented by derived class. 00136 00137 @param inWriteByte Byte to write. 00138 */ 00139 virtual void tty_write( const uint8_t inWriteByte) const = 0; 00140 00141 /** Writes multiple bytes to serial port. 00142 The desired number of bytes to write is specified by the preset length 00143 of the vector parameter. 00144 00145 Abstract method to be implemented by derived class. 00146 00147 @param inWriteBytes Reference to byte vector which contains bytes to write. 00148 */ 00149 virtual void tty_write( const byteVec_t &inWriteBytes) const = 0; 00150 00151 }; 00152 00153 #endif