rllib  1
rlserial.h
Go to the documentation of this file.
1 /***************************************************************************
2  rlserial.cpp - description
3  -------------------
4  begin : Sat Dec 21 2002
5  copyright : (C) 2002 by R. 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  ***************************************************************************/
24 #ifndef _RL_SERIAL_H_
25 #define _RL_SERIAL_H_
26 
27 #include "rlthread.h"
28 
29 #ifdef RLUNIX
30 #include <termios.h>
31 #endif
32 
33 #ifndef B0
34 // speed will be defined by termios.h, this is just for documentation
35 #define B0 0000000 /* hang up */
36 #define B50 0000001
37 #define B75 0000002
38 #define B110 0000003
39 #define B134 0000004
40 #define B150 0000005
41 #define B200 0000006
42 #define B300 0000007
43 #define B600 0000010
44 #define B1200 0000011
45 #define B1800 0000012
46 #define B2400 0000013
47 #define B4800 0000014
48 #define B9600 0000015
49 #define B19200 0000016
50 #define B38400 0000017
51 #define B57600 0010001
52 #define B115200 0010002
53 #define B230400 0010003
54 #define B460800 0010004
55 #define B500000 0010005
56 #define B576000 0010006
57 #define B921600 0010007
58 #define B1000000 0010010
59 #define B1152000 0010011
60 #define B1500000 0010012
61 #define B2000000 0010013
62 #define B2500000 0010014
63 #define B3000000 0010015
64 #define B3500000 0010016
65 #define B4000000 0010017
66 #endif
67 
71 class rlSerial
72 {
73  public:
74  enum Parity
75  {
76  NONE = 0,
77  ODD ,
79  };
80 
81  rlSerial();
82  virtual ~rlSerial();
107  int openDevice(const char *devicename, int speed=B9600, int block=1, int rtscts=1, int bits=8, int stopbits=1, int parity=rlSerial::NONE);
108  int select(int timeout=500);
109  int readChar();
110  int writeChar(unsigned char uchar);
111  int readBlock(unsigned char *buf, int len, int timeout=-1);
112  int writeBlock(const unsigned char *buf, int len);
113  int readLine(unsigned char *buf, int maxlen, int timeout=1000);
114  int closeDevice();
116  void setTrace(int on);
117  private:
118 #ifdef RLUNIX
119  struct termios save_termios;
120 #endif
121 #ifdef __VMS
122  unsigned short int vms_channel;
123 #endif
124 #ifdef RLWIN32
125  HANDLE hdl;
126 #endif
127 #ifdef RM3
128  int device, uint, com, baudrate;
129 #endif
130  enum { RESET, RAW, CBREAK } ttystate;
132  int fd,trace;
133 };
134 
135 #endif
int readBlock(unsigned char *buf, int len, int timeout=-1)
Definition: rlserial.cpp:498
int closeDevice()
Definition: rlserial.cpp:763
virtual ~rlSerial()
Definition: rlserial.cpp:89
void setTrace(int on)
on := 0 | 1 (bool)
Definition: rlserial.cpp:94
enum rlSerial::@4 ttystate
HANDLE hdl
Definition: rlserial.h:125
#define B9600
Definition: rlserial.h:48
int trace
Definition: rlserial.h:132
int readLine(unsigned char *buf, int maxlen, int timeout=1000)
Definition: rlserial.cpp:687
int writeChar(unsigned char uchar)
Definition: rlserial.cpp:454
int select(int timeout=500)
Definition: rlserial.cpp:719
rlSerial()
Definition: rlserial.cpp:81
int openDevice(const char *devicename, int speed=B9600, int block=1, int rtscts=1, int bits=8, int stopbits=1, int parity=rlSerial::NONE)
Definition: rlserial.cpp:100
int readChar()
Definition: rlserial.cpp:405
struct termios save_termios
Definition: rlserial.h:119
unsigned short int vms_channel
Definition: rlserial.h:122
int ttysavefd
Definition: rlserial.h:131
int fd
Definition: rlserial.h:132
int writeBlock(const unsigned char *buf, int len)
Definition: rlserial.cpp:584