/*========================================================================
    Serial.h : Class wrapper for Serial I/O on Linux
  ------------------------------------------------------------------------
    Copyright (C) 1999-2002  James R. Bruce
    School of Computer Science, Carnegie Mellon University
  ------------------------------------------------------------------------
    This software is distributed under the GNU General Public License,
    version 2.  If you do not have a copy of this licence, visit
    www.gnu.org, or write: Free Software Foundation, 59 Temple Place,
    Suite 330 Boston, MA 02111-1307 USA.  This program is distributed
    in the hope that it will be useful, but WITHOUT ANY WARRANTY,
    including MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  ========================================================================*/

#ifndef __SERIAL_H__
#define __SERIAL_H__

class serial{
public:
  int fd;
  serial() {fd=0;}
  serial(const char *device, int baud) {if (!open(device, baud)) fd = 0;}
  ~serial() {close();}

  bool valid() {if (!fd) return false; else return true;}
  bool open(const char *device,int baud);
  void close();
  int getfd() {return fd;}

  int read(void *buf,int size)
    {return(::read(fd,buf,size));}
  int write(const void *buf,int size)
    {return(::write(fd,buf,size));}
};

#endif
