From ffc3028289f925ca547ae06e519221a41837927f Mon Sep 17 00:00:00 2001 From: William Woodall Date: Tue, 30 Jul 2013 10:30:46 -0700 Subject: [PATCH 1/3] Use wstring for port_ type in Windows impl --- include/serial/impl/win.h | 3 ++- src/impl/win.cc | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/serial/impl/win.h b/include/serial/impl/win.h index eb3fe7c..2e3f5ff 100644 --- a/include/serial/impl/win.h +++ b/include/serial/impl/win.h @@ -44,6 +44,7 @@ namespace serial { using std::string; +using std::wstring; using std::invalid_argument; using serial::SerialException; @@ -172,7 +173,7 @@ protected: void reconfigurePort (); private: - string port_; // Path to the file descriptor + wstring port_; // Path to the file descriptor HANDLE fd_; bool is_open_; diff --git a/src/impl/win.cc b/src/impl/win.cc index babde5a..c99ab72 100644 --- a/src/impl/win.cc +++ b/src/impl/win.cc @@ -3,6 +3,7 @@ #include "serial/impl/win.h" using std::string; +using std::wstring; using std::stringstream; using std::invalid_argument; using serial::Serial; @@ -20,7 +21,7 @@ Serial::SerialImpl::SerialImpl (const string &port, unsigned long baudrate, bytesize_t bytesize, parity_t parity, stopbits_t stopbits, flowcontrol_t flowcontrol) - : port_ (port), fd_ (INVALID_HANDLE_VALUE), is_open_ (false), + : port_ (port.begin(), port.end()), fd_ (INVALID_HANDLE_VALUE), is_open_ (false), baudrate_ (baudrate), parity_ (parity), bytesize_ (bytesize), stopbits_ (stopbits), flowcontrol_ (flowcontrol) { @@ -296,13 +297,13 @@ Serial::SerialImpl::write (const uint8_t *data, size_t length) void Serial::SerialImpl::setPort (const string &port) { - port_ = port; + port_ = wstring(port.begin(), port.end()); } string Serial::SerialImpl::getPort () const { - return port_; + return string(port_.begin(), port_.end()); } void From 82884ca519274348d94cf95eefbf3065616e7b17 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Tue, 30 Jul 2013 10:31:15 -0700 Subject: [PATCH 2/3] Pass LPCWSTR to CreateFile in Windows impl This should fix #29 --- src/impl/win.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/impl/win.cc b/src/impl/win.cc index c99ab72..7a27d95 100644 --- a/src/impl/win.cc +++ b/src/impl/win.cc @@ -48,7 +48,8 @@ Serial::SerialImpl::open () throw SerialException ("Serial port already open."); } - fd_ = CreateFile(port_.c_str(), + LPCWSTR lp_port = port_.c_str(); + fd_ = CreateFile(lp_port, GENERIC_READ | GENERIC_WRITE, 0, 0, From 9d20d1a07fa10623f4ed1655806cb57075443ae7 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Tue, 30 Jul 2013 11:04:16 -0700 Subject: [PATCH 3/3] convert wstring into string when printing --- src/impl/win.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/impl/win.cc b/src/impl/win.cc index 7a27d95..acf281a 100644 --- a/src/impl/win.cc +++ b/src/impl/win.cc @@ -62,7 +62,8 @@ Serial::SerialImpl::open () stringstream ss; switch (errno_) { case ERROR_FILE_NOT_FOUND: - ss << "Specified port, " << port_ << ", does not exist."; + // Use this->getPort to convert to a std::string + ss << "Specified port, " << this->getPort() << ", does not exist."; THROW (IOException, ss.str().c_str()); default: ss << "Unknown error opening the serial port: " << errno;