Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

serial.h

Go to the documentation of this file.
00001 /*
00002  * Time-stamp: <00/06/28 23:01:24 pagey>
00003  *
00004  * $Format: " * $Id: serial.h,v 0.0.0.1 2000/06/30 01:58:24 pagey Exp $"$
00005  * serial.h 1.2 Mon, 06 Mar 2000 01:44:21 -0800 pagey
00006  *
00007  */
00008 // 
00009 // FILE:
00010 // serial.h
00011 //
00012 // FUNCTION:
00013 // The linSerial class provides a simple, basic framework
00014 // for managing a serial port.  The design of this class 
00015 // is focused on making serial port easy to use.  The 
00016 // methods are simple and take simple arguments, hiding
00017 // the complexity of the full Linux/Unix termios interface. 
00018 // Only a small portion of the full termios function is 
00019 // exposed; to get at additional function, study the 
00020 // termios(3), stty(1), setserial(8), and statserial(1)
00021 // manual pages.
00022 //
00023 // One convenience offered by this class is fairly verbose
00024 // error message reporting.  Although most methods return
00025 // a non-zero value to indicate that an error has occured,
00026 // one can instead have error, warning and informational
00027 // messages printed to stdout.  See the ErrLog class for 
00028 // details on enabling, disabling, and changing the amount
00029 // of error reporting.
00030 //
00031 // METHODS:
00032 // The OpenDevice() method accepts a file path name and opens
00033 //    it for reading and writing.  The path name can denote 
00034 //    an ordinary file, or a serial port device.  Of course,
00035 //    most of this class cannot be used on ordinary files;
00036 //    ordinary files are supported only for convenience.
00037 //
00038 //    If the pathname points to a serial device, that device
00039 //    is initialized as described in the SetupDefault() method,
00040 //    below.  After the device has been opened, the standard
00041 //    C Language routines fread(), fprintf(), etc. and/or the
00042 //    standard Unix routines read(), write(), select(), etc.
00043 //    can be used.  Use the GetFileDescriptor() and/or the
00044 //    GetFileHandle() methods to get the appropriate handles.
00045 //
00046 //    This method retrun zero if successful, else a non-zero
00047 //    errno value.
00048 //
00049 // The GetFileDescriptor() method returns a file handle which
00050 //    can be used with the Unix read(), write() etc. routines.
00051 //
00052 // The GetFileHandle() method returns a file handle which can 
00053 //    be used with the C Language fread(), fprintf() routines.
00054 //
00055 // The Close() method will close the device.  If the port
00056 //    is attached to a modem, the modem will be hung up when 
00057 //    it is closed.
00058 //
00059 // The SetBits() method can be used to set the number of bits,
00060 //    the parity and the number of stop bits for the port.
00061 //    Bits can be set to 5,6,7 or 8; parity can be set to E,O 
00062 //    or N for Even, Odd, or None, and the stop bits can be set
00063 //    one or two.  Common configurations are 8N1 and 7E2.
00064 //
00065 // The Set8N1() and Set7E2() methods set common bit and parity 
00066 //    configurations.  See the SetBits method for details.
00067 //
00068 // The SetHardwareFlowControl() sets the port to use hardware 
00069 //    flow control. Most modern modems use the RTS/CTS wires
00070 //    of the serial port to avoid buffer overflows.  The 
00071 //    default setting for this class is to use hardware flow 
00072 //    control.
00073 //
00074 // The SetSoftwareFlowControl() sets the port to use software
00075 //    flow control.  Older modems use this, as well as many 
00076 //    serial priinters and mice.  Software flow control sends
00077 //    the ctrl-S and ctrl-Q to stop and start data flow.
00078 //
00079 // The SetSpeed() method sets the speed of the serial port.
00080 //    It takes as an argument an integer denoting the Baud 
00081 //    rate.  For most modern modems, e.g. 14.4, 28.8, etc.
00082 //    set the speed to 115200; the flow control mechanism 
00083 //    will automatically limit the port speed to what the 
00084 //    modem actually connects at.
00085 //
00086 // The SetDTR() method will raise the DTR line.
00087 // The ClearDTR() method will drop the DTR line.
00088 //
00089 // The SetupDefault() method will restore the port setting 
00090 //    to what it was when the OpenDevice() method was called.
00091 //    This defualt setting is as follows:
00092 //    HUPCL  -- the port/modem will hang up when the Close() 
00093 //              method is called.  
00094 //    CTSRTS -- hardware flow control will be used.
00095 //    8N1    -- 8 bits, no parity, one stop bit.
00096 //    IGNBRK -- breaks will be ignored.
00097 //    CBAUD  -- port speed set to 115200
00098 //
00099 // The SetupRaw() method will put the port setting into a 
00100 //    fairly "raw" mode: it will disable special control 
00101 //    characters and canonical control-character processing.
00102 //    That is, there will be no special handling for the 
00103 //    erase, suspend, tab, end-of-line, form-feed, etc. 
00104 //    characters.  
00105 //
00106 //    This method will NOT change the port speed, the 
00107 //    parity and number of stop bits, etc.
00108 //    
00109 // The SetupTerminal() method will put the port setting into a 
00110 //    terminal-like mode: it will enable the canonical
00111 //    processing of the common control characters:
00112 //    erase, suspend, tab, end-of-line, form-feed, etc. 
00113 //
00114 //    This method will NOT change the port speed, the 
00115 //    parity and number of stop bits, etc.
00116 //
00117 // HISTORY:
00118 // Copyright (c) 1995, 1997 Linas Vepstas linas@linas.org
00119 // Released under the  conditions  of  the  GNU General 
00120 // Public License.
00121 
00122 #ifndef __LIN_SERIAL_H__
00123 #define __LIN_SERIAL_H__
00124 
00125 #include <stdio.h>
00126 
00127 #include "errlog.h"
00128 
00129 extern "C++" {
00130   namespace LibGPIB {
00131     class linSerial :
00132       protected linErrLog
00133     {
00134     public:
00135       linSerial (void);
00136 
00137       int OpenDevice  (const char *);
00138       int GetFileDescriptor (void) { return fd; }
00139       FILE * GetFileHandle (void) { return serialport; }
00140       void Close (void);
00141 
00142       int SetupDefault (void);
00143       int SetupRaw (void);
00144       int SetupTerminal (void);
00145 
00146       int SetSpeed (int);
00147 
00148       int SetHardwareFlowControl (void) { return SetFlowControl (1); }
00149       int SetSoftwareFlowControl (void) { return SetFlowControl (0); }
00150 
00151       int SetBits (int, char, int);
00152       int Set8N1 (void) { return SetBits (8, 'N', 1); }
00153       int Set7E2 (void) { return SetBits (7, 'E', 2); }
00154 
00155       void SetDTR (void);
00156       void ClearDTR (void);
00157 
00158     protected:
00159       int SetFlowControl (int);
00160 
00161       int fd;                   // file descriptor
00162       FILE * serialport;
00163       char * filename;
00164 
00165     private:
00166       int speed;
00167       short istty;
00168     };
00169   } // namespace LibGPIB
00170 } // extern "C++" 
00171 #endif /* __LIN_SERIAL_H__ */
00172 // ====================== END OF FILE ============================

Generated at Tue Aug 8 01:37:55 2000 for libgpib by doxygen1.1.4 written by Dimitri van Heesch, © 1997-2000