home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / c / cuj9301.zip / 1101056A < prev    next >
Text File  |  1992-11-09  |  1KB  |  49 lines

  1. #if !defined SERIAL_H
  2. #define SERIAL_H
  3.  
  4. #include <iostream.h>
  5.  
  6. class ComBuffer;    // forward declaration
  7.  
  8. // This class represents everything needed for the 
  9. // template parameter.  It has a default constructor,
  10. // open, close, read, write, seek, and status.
  11. class SerialStream {
  12. public:
  13. // Default constructor.  Initialize an unopened stream
  14.     SerialStream() 
  15.         : port(-1)
  16.     { 
  17.     }
  18. // Destructor.  calls close.
  19.     ~SerialStream()
  20.     {
  21.         close();
  22.     }
  23. // The open function sets up the default serial port
  24. // parameters, and hook up the interrupts.  The name
  25. // is check for "COM1" and "COM2".  mode and prot are
  26. // ignored.
  27.     int open(const char *name, int mode, int prot);
  28. // Read fills buf with len characters from the
  29. // circular buffer.  This class and any class that 
  30. // cannot seek should be unbuffered, so read typically
  31. // asks for one character at a time.
  32.     int read(char *buf, size_t len);
  33. // Write sends the characters in buf to the port.
  34.     int write(char *buf, size_t len);
  35. // Seek is a dummy function and always retruns error.
  36.     long seek(long, ios::seek_dir) { return -1; }
  37. // close set the port number to -1 for open testing.
  38.     int close();
  39. // This function is the status function.
  40.     operator const void *() { return port == -1 ? 0 : 
  41.                                             this; }
  42. private:
  43.     int port;
  44.     ComBuffer *buffPtr;
  45. };
  46.  
  47. #endif
  48.  
  49.