direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
direcsSerial.h
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) Markus Knapp *
3  * www.direcs.de *
4  * *
5  * This file is part of direcs. *
6  * *
7  * direcs is free software: you can redistribute it and/or modify it *
8  * under the terms of the GNU General Public License as published *
9  * by the Free Software Foundation, version 3 of the License. *
10  * *
11  * direcs is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with direcs. If not, see <http://www.gnu.org/licenses/>. *
18  * *
19  *************************************************************************/
20 
21 
22 #ifndef DIRECS_SERIAL_H
23 #define DIRECS_SERIAL_H
24 
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <math.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <termios.h>
32 #include <unistd.h>
33 #include <sys/types.h>
34 #include <sys/ioctl.h>
35 #include <sys/stat.h>
36 #include <sys/time.h>
37 
38 #include <QtGlobal> // for Q_OS_* Makro!
39 
40 #ifdef CYGWIN
41 #include <sys/socket.h>
42 #else
43 
44 #ifdef Q_OS_LINUX
45 #include <linux/serial.h>
46 #endif
47 
48 #endif
49 
50 #define READ_TIMEOUT 250000
51 #define READ_TIMEOUT_ATMEL 250000
52 #define _POSIX
53 
54 #include <QtGlobal>
55 #include <QString>
56 #include <QDebug>
57 
58 
65 class DirecsSerial : public QObject
66 {
67  Q_OBJECT
68 
69  public:
70  DirecsSerial();
71  ~DirecsSerial();
72 
82  int openPort(char *dev_name, int baudrate);
83 
89  int purgeRx();
90 
98  int writeData(unsigned char *c, QString callingClassName = "none");
99 
108  int readData(unsigned char *buf, int nChars, QString callingClassName = "none");
109 
115  int closePort();
116 
117 
118  signals:
123  void message(QString text);
124 
125 
126  private:
127  QString className;
128 
129  int mDev_fd;
130 };
131 
132 #endif