Subversion Repositories HomeAutomation

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  /***************************************************************************
  2.                            rlserial.cpp  -  description
  3.                               -------------------
  4.      begin                : Sat Dec 21 2002
  5.      copyright            : (C) 2002 by Rainer Lehrig
  6.      email                : lehrig@t-online.de
  7.  
  8.      RMOS implementation:
  9.      Copyright            : (C) 2004 Zertrox GbR
  10.      Written by           : Alexander Feller
  11.      Email                : feller@zertrox.de
  12.   ***************************************************************************/
  13.  
  14.  /***************************************************************************
  15.   *                                                                         *
  16.   *   This library is free software; you can redistribute it and/or modify  *
  17.   *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
  18.   *   published by the Free Software Foundation                             *
  19.   *                                                                         *
  20.   ***************************************************************************/
  21.  #ifndef _RL_SERIAL_H_
  22.  #define _RL_SERIAL_H_
  23.  
  24.  #include "rlthread.h"
  25.  
  26.  #ifdef unix
  27.  #include <termios.h>
  28.  #endif
  29.  
  30.  #ifndef B0
  31.  // speed will be defined by termios.h, this is just for documentation
  32.  #define  B0       0000000  /* hang up */
  33.  #define  B50      0000001
  34.  #define  B75      0000002
  35.  #define  B110     0000003
  36.  #define  B134     0000004
  37.  #define  B150     0000005
  38.  #define  B200     0000006
  39.  #define  B300     0000007
  40.  #define  B600     0000010
  41.  #define  B1200    0000011
  42.  #define  B1800    0000012
  43.  #define  B2400    0000013
  44.  #define  B4800    0000014
  45.  #define  B9600    0000015
  46.  #define  B19200   0000016
  47.  #define  B38400   0000017
  48.  #define  B57600   0010001
  49.  #define  B115200  0010002
  50.  #define  B230400  0010003
  51.  #define  B460800  0010004
  52.  #define  B500000  0010005
  53.  #define  B576000  0010006
  54.  #define  B921600  0010007
  55.  #define  B1000000 0010010
  56.  #define  B1152000 0010011
  57.  #define  B1500000 0010012
  58.  #define  B2000000 0010013
  59.  #define  B2500000 0010014
  60.  #define  B3000000 0010015
  61.  #define  B3500000 0010016
  62.  #define  B4000000 0010017
  63.  #endif
  64.  
  65.  class rlSerial
  66.  {
  67.    public:
  68.      enum Parity
  69.      {
  70.        NONE = 0,
  71.        ODD ,
  72.        EVEN
  73.      };
  74.  
  75.      rlSerial();
  76.      ~rlSerial();
  77.      int openDevice(const char *devicename, int speed=B9600, int block=1, int rtscts=1, int bits=8, int stopbits=1, int parity=rlSerial::NONE);
  78.      int select(int timeout=500);
  79.      int readChar();
  80.      int writeChar(unsigned char uchar);
  81.      int readBlock(unsigned char *buf, int len);
  82.      int writeBlock(const unsigned char *buf, int len);
  83.      int readLine(unsigned char *buf, int maxlen);
  84.      int closeDevice();
  85.      void setTrace(int on);
  86.    private:
  87.  #ifdef unix
  88.      struct termios save_termios;
  89.  #endif
  90.  #ifdef __VMS
  91.      unsigned short int vms_channel;
  92.  #endif
  93.  #ifdef _WIN32
  94.      HANDLE hdl;
  95.  #endif
  96.  #ifdef RM3
  97.      int device, uint, com, baudrate;
  98.  #endif
  99.      enum { RESET, RAW, CBREAK } ttystate;
  100.      int ttysavefd;
  101.      int fd,trace;
  102.  };
  103.  
  104.  #endif
  105.