Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

dsSerial.h

Go to the documentation of this file.
00001 /*
00002  * $Id: dsSerial.h,v 1.8 2004/06/25 08:25:03 dsamersoff Exp $
00003  *
00004  *
00005  */
00006 
00007 
00008 #ifndef dsSerial_h
00009 #define dsSerial_h
00010 
00011 
00012 #ifdef HAVE_CONFIG_H
00013 # include <config.h>
00014 #endif
00015 
00016 #include <stdlib.h>
00017 #include <errno.h>
00018 #include <fcntl.h>
00019 #include <sys/types.h>
00020 #include <sys/stat.h>
00021 
00022 #ifdef Win32
00023 # include <windows.h>
00024 #else
00025 # include <sys/ioctl.h>
00026 # include <termios.h>
00027 # include <sys/types.h>
00028 # include <signal.h>
00029 #endif
00030 
00031 #ifdef Solaris
00032 #include <sys/filio.h>
00033 #endif
00034 
00035 #ifdef HAVE_UNISTD_H
00036 # include <unistd.h>
00037 #endif
00038 
00039 #include <iostream>
00040 
00041 #include <dsSmartException.h>
00042 #include <dsutil.h>
00043 
00044 DECLARE_EXCEPTION(dsSerial);
00045 
00046 enum { OP_READ, OP_WRITE };
00047 
00048 class dsSerial
00049 {
00050 protected:
00051 
00052   int _flags; 
00053   int _speed;
00054   char *_dev;  
00055 
00056 #ifdef Win32
00057   DCB *_oldtio;
00058   HANDLE _hSerial;
00059   OVERLAPPED _osWrite, _osRead;
00060 #else
00061   termios * _oldtio;
00062   termios * _newtio;
00063   int _hSerial;
00064 #endif
00065 
00066 public:
00067    dsSerial();
00068    dsSerial(const char *tty, int speed, int flags);
00069   ~dsSerial();
00070 
00071    void Open(const char *tty, int speed, int flags);
00072    void Open();
00073    void Close();
00074 
00075    void Lock(const char *tty, const char *lockdir = "/var/run" );
00076    void UnLock(const char *tty, const char *lockdir = "/var/run" );
00077 
00078 
00079    void setDtr(bool set = true);
00080    void setRts(bool set = true);
00081 
00082    bool testCts();
00083    int  readQueueSize();
00084 
00085    void changeSpeed(int speed);
00086 
00087    int  Select(struct timeval *timeout, int op = OP_READ);
00088    size_t Read(char *buf, size_t nbytes, int sec = 10, int usec = 0);
00089    int ReadLine(std::ostream& os, int sec = 10, int usec = 0);
00090    size_t Write(const char *buf, size_t nbytes);
00091 
00092 #ifdef Win32
00093     HANDLE fd();
00094 #else
00095     int fd();
00096 #endif  
00097 };
00098 
00099 #endif

Generated on Mon May 16 18:26:58 2005 for libdms4 by doxygen1.3-rc2