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