-
Notifications
You must be signed in to change notification settings - Fork 11
/
SerialPort.h
113 lines (85 loc) · 3.25 KB
/
SerialPort.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/****************************************************************************
*
* Copyright (c) 2005 - 2008 Dave Hylands <dhylands@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* See README and COPYING for more details.
*
****************************************************************************/
/**
*
* @file SerialPort.h
*
* @brief This file contains the definitions for the SerialPort class.
*
****************************************************************************/
/**
* @defgroup SerialPort Serial Port
*
* @brief Performs serial communications using Unix style serial ports.
*
****************************************************************************/
#pragma once
// ---- Include Files -------------------------------------------------------
#include <stddef.h>
#include <stdint.h>
#if defined(WIN32)
#include <windows.h>
#endif
/**
* @addtogroup SerialPort
* @{
*/
//---------------------------------------------------------------------------
/**
* The SerialPort class encapsulates serial port communcations using
* unix style serial communications. This also works under cygwin (for Win32)
*/
class SerialPort {
public:
//------------------------------------------------------------------------
// Default constructor
SerialPort();
//------------------------------------------------------------------------
// Destructor
~SerialPort();
//------------------------------------------------------------------------
// Opens a serial port.
bool Open(const char* devName, const char* param = NULL);
//------------------------------------------------------------------------
// Closes a previsouly opened serial port.
void Close();
//------------------------------------------------------------------------
// Reads data from the serial port.
size_t Read(void* buf, size_t bytesToRead);
//------------------------------------------------------------------------
// Sets the timeout to use when waiting for data. 0 = infinite
// The timeout is specified in milliseconds.
bool SetTimeout(unsigned timeout);
//------------------------------------------------------------------------
// Writes data to the serial port.
size_t Write(const void* buf, size_t bytesToWrite);
//------------------------------------------------------------------------
// Strobes the DTR and RTS lines.
void StrobeDTRRTS();
private:
//------------------------------------------------------------------------
// The copy constructor and assignment operator are not need for this
// class so we declare them private and don't provide an implementation.
SerialPort(const SerialPort& copy);
SerialPort& operator=(const SerialPort& rhs);
//------------------------------------------------------------------------
#if defined(WIN32)
HANDLE m_serialHndl;
#else
int m_fd;
#endif
};
// ---- Inline Functions ----------------------------------------------------
/** @} */