HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Serial.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Serial.h ( Channel Operator Library, C++)
7  *
8  * COMMENTS:
9  *
10  * Implements an interface to the serial port interface.
11  *
12  */
13 #ifndef UT_SERIAL_H
14 #define UT_SERIAL_H
15 
16 #include "UT_API.h"
17 #include "UT_NonCopyable.h"
18 #ifdef WIN32
19 #include <windows.h>
20 #include <winbase.h>
21 #else
22 #define _OLD_TERMIOS
23 #include <termios.h>
24 #endif
25 
26 #define SERIAL_NO_PARITY 0
27 #define SERIAL_ODD_PARITY 1
28 #define SERIAL_EVEN_PARITY 2
29 
31 {
32 public:
33  explicit UT_Serial(int rate = 9600,
34  int databits = 8,
35  int parity = SERIAL_NO_PARITY,
36  int stopbits = 1);
37 
38  virtual ~UT_Serial();
39 
41 
42  int open(const char *port, int parms);
43  void close();
44 
45  int changeRate(int rate);
46 
47  int dataAvailable();
48  int read(void *buffer, int num);
49  int write(const void *buffer, int num);
50 
51  void flush();
52 
53 private:
54  int mySpeed;
55  int myDataBits;
56  int myStopBits;
57  int myParity;
58 
59  // platform specific
60 #ifdef WIN32
61  HANDLE myFD;
62  COMMCONFIG myPreviousState;
63  COMMCONFIG mySerialState;
64  int myDataAvailable;
65  char myStoredChar;
66 #else
67  int myFD;
68  struct termios myPreviousState;
69  struct termios mySerialState;
70 #endif
71 };
72 
73 #endif
#define UT_API
Definition: UT_API.h:14
void close() override
Definition: core.h:760
int open(float queuesize) override
#define SERIAL_NO_PARITY
Definition: UT_Serial.h:26
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.