-
Notifications
You must be signed in to change notification settings - Fork 0
/
Serial.h
67 lines (55 loc) · 1.62 KB
/
Serial.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
/** Serial.h
*
* A very simple serial port control class that does NOT require MFC/AFX.
*
* License: This source code can be used and/or modified without restrictions.
* It is provided as is and the author disclaims all warranties, expressed
* or implied, including, without limitation, the warranties of
* merchantability and of fitness for any purpose. The user must assume the
* entire risk of using the Software.
*
* @author Hans de Ruiter
*
* @version 0.1 -- 28 October 2008
*/
#ifndef __SERIAL_H__
#define __SERIAL_H__
#include <string>
#include <windows.h>
typedef std::basic_string<TCHAR> tstring;
class Serial
{
private:
HANDLE commHandle;
public:
Serial(tstring &commPortName, int bitRate = 115200);
virtual ~Serial();
/** Writes a NULL terminated string.
*
* @param buffer the string to send
*
* @return int the number of characters written
*/
int write(const char buffer[]);
/** Writes a string of bytes to the serial port.
*
* @param buffer pointer to the buffer containing the bytes
* @param buffLen the number of bytes in the buffer
*
* @return int the number of bytes written
*/
int write(const char *buffer, int buffLen);
/** Reads a string of bytes from the serial port.
*
* @param buffer pointer to the buffer to be written to
* @param buffLen the size of the buffer
* @param nullTerminate if set to true it will null terminate the string
*
* @return int the number of bytes read
*/
int read(char *buffer, int buffLen, bool nullTerminate = true);
/** Flushes everything from the serial port's read buffer
*/
void flush();
};
#endif