-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerialPort.h
48 lines (39 loc) · 1.09 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
#ifndef _SERIALPORT_H_
#define _SERIALPORT_H_
#include <windows.h>
// load in the multimedia library
#ifdef _MSC_VER
#pragma comment(lib,"winmm.lib")
#endif
class SerialPort
{
public:
void Set_RTS_State(bool state);
void Set_DTR_State(bool state);
bool Get_RI_State();
bool Get_DSR_State();
bool Get_CTS_State();
bool Get_CD_State();
bool ChangeBaudRate (int buadRate);
bool SetHardwareControl(bool hardwareControl);
bool Write(const char* Buffer, unsigned long BufferSize);
int Read(char* buffer, unsigned long bufferSize, unsigned int msWait);
int ReadByte(char* buffer, unsigned int msWait);
bool IsOpen();
void Close();
// Use PortName usually "COM1:" ... "COM4:" note that the name must end by ":"
virtual bool Open(TCHAR* PortName,
unsigned long BaudRate = 9600,
unsigned char ByteSize = 8,
unsigned char Parity = NOPARITY,
unsigned char StopBits = ONESTOPBIT,
unsigned long DesiredAccess = GENERIC_READ|GENERIC_WRITE);
SerialPort();
virtual ~SerialPort();
protected:
int wrRetries;
int rdRetries;
DCB dcb;
HANDLE m_PortHandle;
};
#endif // _SERIALPORT_H_