37 #define WIN32_LEAN_AND_MEAN
44 HANDLE hCom = CreateFile(port.c_str(), GENERIC_READ | GENERIC_WRITE,
54 if (INVALID_HANDLE_VALUE == hCom) {
55 auto err = GetLastError();
56 if (ERROR_ACCESS_DENIED == err) {
87 if (port.find(
'\\') == std::string::npos) {
88 return "\\\\.\\" + port;
95 std::string
const *origPortPtr = origPort.empty() ? &port : &origPort;
98 throw std::runtime_error(
"Cannot access " + *origPortPtr +
99 ": currently busy. Do you have another "
100 "application open using that port?");
102 throw std::runtime_error(
"Cannot access " + *origPortPtr +
103 ": port apparently not found. Make sure the "
104 "device is plugged in and you've specified "
105 "the right device and the right port.");
107 throw std::runtime_error(
"Cannot access serial port '" + *origPortPtr +
108 "': apparently invalid.");
111 throw std::runtime_error(
"Cannot access serial port '" + *origPortPtr +
Header declaring a C++11 finally or "scope-guard" construct.
std::string normalizeSerialPort(std::string const &port)
Normalizes the name of a serial port.
SerialPortState getSerialPortState(std::string const &port)
Returns an enum value indicating the apparent state of the port.
void verifySerialPort(std::string const &port, std::string const &origPort)
Verifies the accessibility of a serial port and throws a std::exception unless it is available...
Something's wrong with the port name you gave.
FinalTask< F > finally(F &&f)
serial port requested is missing.
std::string normalizeAndVerifySerialPort(std::string const &port)
Normalizes and verifies the accessibility of a serial port and throws a std::exception unless it is a...
SerialPortState getSerialPortStateImpl(std::string const &port)