SerialPort
A light-weight C++ library for cross-platform serial communication.
Loading...
Searching...
No Matches
serial_port_windows.h
1#ifndef SERIAL_PORT_WINDOWS_H_
2#define SERIAL_PORT_WINDOWS_H_
3
4#if defined(_WIN32)
5
6#include <serial_port/serial_port.h>
7
8#include "interface.h"
9#include <Windows.h>
10
11namespace serial_port
12{
13 class SerialPortWindows final : public Interface
14 {
15 public:
16 // Inherit the constructors from the interface
17 using Interface::Interface;
18
19 // Allow moving a serial port
20 SerialPortWindows(SerialPortWindows&&) = default;
21 SerialPortWindows& operator=(SerialPortWindows&& other) = default;
22 // Do not allow copying a serial port
23 SerialPortWindows(const SerialPortWindows&) = delete;
24 SerialPortWindows& operator=(const SerialPortWindows& other) = delete;
25
26 // Make sure the port gets properly closed on destruction
27 ~SerialPortWindows() override { SerialPortWindows::Close(); }
28
29 // Implement the interface
30 void Open() override;
31 void Close() override;
32 bool IsOpen() override;
33
34 unsigned long NumBytesAvailable() override;
35 void FlushBuffer() const override;
36
37 unsigned long ReadData(char* data, unsigned long num_bytes) override;
38 unsigned long WriteData(const char* data, unsigned long num_bytes) override;
39
40 private:
41 HANDLE handle_{ INVALID_HANDLE_VALUE };
42 COMMCONFIG comm_config_;
43 // ReSharper disable once CommentTypo
44 // COMMTIMEOUTS comm_timeouts_;
45 };
46}
47
48#endif // _WIN32
49
50#endif // !SERIAL_PORT_WINDOWS_H_
51
52