-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerialCom.h
44 lines (38 loc) · 990 Bytes
/
SerialCom.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
#pragma once
#include <Windows.h>
#include <cstdio>
#define _CRT_SECURE_NO_WARNINGS
namespace Robot{
#define DEVICES_BUF_SIZE 1024
#define RECEIVE_BUF_SIZE 1024
int getSerialPortNumbers(int *comPortTable, int num_max);
class SerialCom
{
private:
char portName[128];
int portNum = 0;
int boundRate = 9600;
int writeBufSize = 0;
int receiveBufLength = 0;
HANDLE portHandle;
char receiveBuffer[RECEIVE_BUF_SIZE];
BYTE *writeBuffer;
HANDLE threadHandle;
int threadId = 0;
HANDLE mutexHandle;
bool threadExitFlag;
static DWORD WINAPI threadFunc(LPVOID pthis);
int threadMain();
public:
SerialCom();
SerialCom(char *_portName, int _boundRate);
SerialCom(char *_portName, int _boundRate, int _writeBufSize);
~SerialCom();
bool init(char *_portName, int _boundRate, int _writeBufSize);
bool exit();
void send(char *_transString);
int read(char *_buf, int _bufSize);
void clearReadBuffer();
void testCom(char *retBuf, int retBufSize);
};
}