mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-23 04:04:54 +08:00
Merge 07837271dd4914d9de233919bb92c1453d919cda into 7e04501d99465a5fdeb3d5922ae617b4e27553db
This commit is contained in:
commit
1ea0af500f
@ -16,6 +16,20 @@ using serial::PortNotOpenedException;
|
|||||||
using serial::IOException;
|
using serial::IOException;
|
||||||
|
|
||||||
|
|
||||||
|
// Convert std::string to LPCWSTR
|
||||||
|
// http://stackoverflow.com/questions/27220/how-to-convert-stdstring-to-lpcwstr-in-c-unicode
|
||||||
|
std::wstring s2ws(const std::string& s)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
int slength = (int)s.length() + 1;
|
||||||
|
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
|
||||||
|
wchar_t* buf = new wchar_t[len];
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
|
||||||
|
std::wstring r(buf);
|
||||||
|
delete[] buf;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
Serial::SerialImpl::SerialImpl (const string &port, unsigned long baudrate,
|
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,
|
||||||
@ -47,7 +61,9 @@ Serial::SerialImpl::open ()
|
|||||||
throw SerialException ("Serial port already open.");
|
throw SerialException ("Serial port already open.");
|
||||||
}
|
}
|
||||||
|
|
||||||
fd_ = CreateFile(port_.c_str(),
|
std::wstring stemp = s2ws(port_);
|
||||||
|
LPCWSTR lpFileName = stemp.c_str();
|
||||||
|
fd_ = CreateFile(lpFileName,
|
||||||
GENERIC_READ | GENERIC_WRITE,
|
GENERIC_READ | GENERIC_WRITE,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user