forked from NOVACProject/MobileDOAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialConnection.h
More file actions
88 lines (66 loc) · 2.92 KB
/
Copy pathSerialConnection.h
File metadata and controls
88 lines (66 loc) · 2.92 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
#pragma once
class CSerialConnection final
{
public:
CSerialConnection();
~CSerialConnection();
// --- Moving the CSerialConnection is allowed
CSerialConnection(CSerialConnection&& other);
CSerialConnection& operator=(CSerialConnection&& other);
// --- This class manages a serial connction handle and is thus not copyable
CSerialConnection(const CSerialConnection& ) = delete;
CSerialConnection& operator=(const CSerialConnection&) = delete;
/** Initializes the serial port communication using the provided speed and port number.
@param speed The baudrate to use.
@param portNumber The index of the port to use (e.g. 0 for COM0 or 3 for COM3)
@return true If the connection was successfully opened, otherwise false. */
bool Init(int portNumber, long speed);
/** Initializes the serial port communication using the provided speed and a previously set port number.
@param speed The baudrate to use.
@return true If the connection was successfully opened, otherwise false. */
bool Init(long speed);
/** Initializes the serial port communication using an already set port and baudrate.
This may be called after calling Init() (and closing the connection) OR after calling
SetBaudrate(...) and SetPort(...).
@return true If the connection was successfully opened, otherwise false. */
bool Init();
/** Setting the baudrate */
void SetBaudrate(long speed) { this->baudrate = speed; }
/** Setting the com-port to use */
void SetPort(int portNumber);
void SetPort(const CString& port);
/** Getting the status */
long GetBaudrate() const { return this->baudrate; }
const char* GetPort() const { return this->serialPort;}
/** Checks the serial port for more data.
@param timeOut The serial read timeout, in milliseconds.
@return true if there is more data to be read out from 'Read' */
bool Check(long timeOut);
void Write(void *ptTxt,long byteNum);
long Read(void *ptBuf,long byteNum);
void FlushSerialPort(long timeOut);
void Close();
int InitCommunication();
int ChangeBaudRate();
void CloseAll();
int ResetSpectrometer(long speed);
// ---------------- Status of the communication ----------------
/* Pointer to a running flag (in spectrometer->runFlag).
If this is set (!= nullptr) then this flag will be checked before reading
the gps and the reading will cancelled if this flag is set to false. */
volatile bool* isRunning = nullptr;
private:
// This is the handle to the serial port communication
HANDLE hComm;
/* data definition */
char serbuf[10]; // the serial communication buffer
int serbufpt; // current character is serbuf[serbufpt]
char serialPort[20];
long m_delay; /* communication delay */
long baudrate; // spectrometer baudrate
long sysBaud; // system baudrate
long br2;
long br1;
//CString *statusMsg; /* pointer to spectrometer->m_statusMsg */
int startChn, stopChn;
};