-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialport.h
73 lines (63 loc) · 1.69 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
#ifndef SERIALPORT_H
#define SERIALPORT_H
#include <windows.h>
enum Baudrate
{
B50 = 50,
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
};
enum Stopbits
{
one = ONESTOPBIT,
onePointFive = ONE5STOPBITS,
two = TWOSTOPBITS
};
enum Paritycheck
{
even = EVENPARITY,
odd = ODDPARITY,
off = NOPARITY,
mark = MARKPARITY
};
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);
void closeSerialPort(HANDLE hSerial);
#endif