mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 11:44:53 +08:00
Merge pull request #30 from wjwwood/fix_wstring_windows
Fix wide string usage in Windows impl
This commit is contained in:
commit
329545b282
@ -44,6 +44,7 @@
|
|||||||
namespace serial {
|
namespace serial {
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::wstring;
|
||||||
using std::invalid_argument;
|
using std::invalid_argument;
|
||||||
|
|
||||||
using serial::SerialException;
|
using serial::SerialException;
|
||||||
@ -172,7 +173,7 @@ protected:
|
|||||||
void reconfigurePort ();
|
void reconfigurePort ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string port_; // Path to the file descriptor
|
wstring port_; // Path to the file descriptor
|
||||||
HANDLE fd_;
|
HANDLE fd_;
|
||||||
|
|
||||||
bool is_open_;
|
bool is_open_;
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include "serial/impl/win.h"
|
#include "serial/impl/win.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::wstring;
|
||||||
using std::stringstream;
|
using std::stringstream;
|
||||||
using std::invalid_argument;
|
using std::invalid_argument;
|
||||||
using serial::Serial;
|
using serial::Serial;
|
||||||
@ -20,7 +21,7 @@ Serial::SerialImpl::SerialImpl (const string &port, unsigned long baudrate,
|
|||||||
bytesize_t bytesize,
|
bytesize_t bytesize,
|
||||||
parity_t parity, stopbits_t stopbits,
|
parity_t parity, stopbits_t stopbits,
|
||||||
flowcontrol_t flowcontrol)
|
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),
|
baudrate_ (baudrate), parity_ (parity),
|
||||||
bytesize_ (bytesize), stopbits_ (stopbits), flowcontrol_ (flowcontrol)
|
bytesize_ (bytesize), stopbits_ (stopbits), flowcontrol_ (flowcontrol)
|
||||||
{
|
{
|
||||||
@ -47,7 +48,8 @@ Serial::SerialImpl::open ()
|
|||||||
throw SerialException ("Serial port already 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,
|
GENERIC_READ | GENERIC_WRITE,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@ -60,7 +62,8 @@ Serial::SerialImpl::open ()
|
|||||||
stringstream ss;
|
stringstream ss;
|
||||||
switch (errno_) {
|
switch (errno_) {
|
||||||
case ERROR_FILE_NOT_FOUND:
|
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());
|
THROW (IOException, ss.str().c_str());
|
||||||
default:
|
default:
|
||||||
ss << "Unknown error opening the serial port: " << errno;
|
ss << "Unknown error opening the serial port: " << errno;
|
||||||
@ -296,13 +299,13 @@ Serial::SerialImpl::write (const uint8_t *data, size_t length)
|
|||||||
void
|
void
|
||||||
Serial::SerialImpl::setPort (const string &port)
|
Serial::SerialImpl::setPort (const string &port)
|
||||||
{
|
{
|
||||||
port_ = port;
|
port_ = wstring(port.begin(), port.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
string
|
string
|
||||||
Serial::SerialImpl::getPort () const
|
Serial::SerialImpl::getPort () const
|
||||||
{
|
{
|
||||||
return port_;
|
return string(port_.begin(), port_.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user