-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerial.h
33 lines (22 loc) · 967 Bytes
/
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
#pragma once
#define MAX_BUFFER_SIZE (1024*4)
#define INVALID_PORT_NUM (-1)
class CSerial
{
public:
CSerial();
~CSerial();
BOOL OpenPort( int Port , DWORD dwBaud , BYTE byData , BYTE byStop , BYTE byParity , DWORD& LastError );
void ClosePort();
DWORD Send( const BYTE* pBuff , DWORD Size );
DWORD Read( BYTE* pBuff , DWORD nToRead );
DWORD SendAndRead( const BYTE* pSend , DWORD SendSize , BYTE* ResBuffer , DWORD ResBufferSize , DWORD WaitTick = 100 );
inline BOOL IsConnected() const { return GetComPortNum() != INVALID_PORT_NUM; }
inline int GetComPortNum() const { return m_ComPort; }
private:
CRITICAL_SECTION m_cs;
OVERLAPPED m_osRead; // 포트 파일 Overlapped structure
OVERLAPPED m_osWrite; // 포트 파일 Overlapped structure
HANDLE m_hComm = INVALID_HANDLE_VALUE; // 통신 포트 파일 핸들
int m_ComPort = INVALID_PORT_NUM; // 현재 연결된 컴포트 번호( INVALID_PORT_NUM(-1) 는 연결 상태가 아니다 )
};