-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathserialport.h
92 lines (83 loc) · 2.56 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
#ifndef SERIALPORT_H
#define SERIALPORT_H
#include <windows.h>
/**
* \brief A list of standard baudrates
* \note there may be additional conigurations available for your hardware
*/
enum Baudrate
{
B50 = 50, // not listed in https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-dcb
B110 = 110,
B150 = 150,
B300 = 300,
B1200 = 1200,
B2400 = 2400,
B4800 = 4800,
B9600 = 9600,
B19200 = 19200,
B38400 = 38400,
B57600 = 57600,
B115200 = 115200,
B230400 = 230400,
B460800 = 460800,
B500000 = 500000,
B1000000= 1000000 // not listed in https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-dcb
};
/**
* \brief Possible values for the nuber of stop bits
*/
enum Stopbits
{
one = ONESTOPBIT,
onePointFive = ONE5STOPBITS,
two = TWOSTOPBITS
};
/**
* \brief Available parity operation modes modes
*/
enum Paritycheck
{
off = NOPARITY, // disable parity checking
even = EVENPARITY, // enable even parity
odd = ODDPARITY, // enable odd parity
mark = MARKPARITY, // enable mark parity
space = SPACEPARITY // enable space parity
};
/**
* \brief Display the error information from the operation system and exit the program.
* \param lpszFunction Additional input for the user printed before the error message.
*/
void ErrorExit(LPTSTR lpszFunction);
/**
\brief Opens a new connection to a serial port
\param portname name of the serial port(COM1 - COM9 or \\\\.\\COM1-COM256)
\param baudrate the baudrate of this port (for example 9600)
\param stopbits th nuber of stoppbits (one, onePointFive or two)
\param parity the parity (even, odd, off or mark)
\return HANDLE to the serial port
*/
HANDLE openSerialPort(LPCSTR portname,enum Baudrate baudrate, enum Stopbits stopbits, enum Paritycheck parity);
/**
\brief Read data from the serial port
\param hSerial File HANDLE to the serial port
\param buffer pointer to the area where the read data will be written
\param buffersize maximal size of the buffer area
\return amount of data that was read
*/
DWORD readFromSerialPort(HANDLE hSerial, char * buffer, int buffersize);
/**
\brief write data to the serial port
\param hSerial File HANDLE to the serial port
\param buffer pointer to the area where the read data will be read
\param length amount of data to be read
\return amount of data that was written
*/
DWORD writeToSerialPort(HANDLE hSerial, char * data, int length);
/**
* Close the port
* \param hSerial File HANDLE to the serial port that need to be closed
* Will return false on success
*/
BOOL closeSerialPort(HANDLE hSerial);
#endif