-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCOM_Communication.h
More file actions
100 lines (72 loc) · 1.95 KB
/
COM_Communication.h
File metadata and controls
100 lines (72 loc) · 1.95 KB
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
93
94
95
96
97
98
99
100
#pragma once
#pragma warning(disable : 4996)
#include <winsock2.h>
#include <Windows.h>
#include <thread>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <mutex>
#include <condition_variable>
#include "wx/wx.h"
#include "dataPanel.h"
class COM_Communication
{
public:
COM_Communication();
~COM_Communication();
public:
// ---------- COM communication ---------- //
void ConfigureComPort(DWORD);
void SetTimeouts();
void WriteComPort(unsigned char& buff);
void ConnectHandle(LPCWSTR COM_PORT);
void DisconnectHandle();
// ----------- Thread handling ----------- //
void InitCOMReader(dataPanel* rawPanel);
void ReadIncomingData(dataPanel* rawPanel);
void pauseReadingData();
void resumeReadingData();
// Get status of COM_Recv
wxString GetStatus();
void SetStatus(wxString);
std::thread threadHandler;
private:
HANDLE hSerial;
wxString status;
std::mutex mutex_;
std::condition_variable cv;
std::atomic<bool> shouldPause = { false };
std::atomic<bool> shouldRun = { true };
};
/*
void cMain::ConnButtonClicked(wxCommandEvent& evt)
{
com_recv = new COM_Recv(c_ComSelector->GetStringSelection());
t_DataText->AppendText(com_recv->GetStatus());
com_recv->ConfigureComPort(wxAtoi(c_BaudSelector->GetStringSelection()));
t_DataText->AppendText(com_recv->GetStatus());
com_recv->SetTimeouts();
t_DataText->AppendText(com_recv->GetStatus());
unsigned char BytesArr = ' ';
while (disconnCheck)
{
if (!isSending)
{
if (com_recv->ReadComPort(BytesArr))
{
std::ostringstream oss;
// Format the byte as hexadecimal and save it into the stringstream
oss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(BytesArr);
// Extract the string from the stringstream
std::string hexString = oss.str();
t_DataText->AppendText(hexString + " ");
}
}
wxYield();
}
t_DataText->AppendText("Handle killed\n");
disconnCheck = true;
evt.Skip();
}
*/