diff --git a/examples/serial_example.cc b/examples/serial_example.cc index 6b29803..59d8f7c 100644 --- a/examples/serial_example.cc +++ b/examples/serial_example.cc @@ -55,7 +55,11 @@ int run(int argc, char **argv) // Argument 2 is the baudrate unsigned long baud = 0; +#ifdef WIN32 + sscanf_s(argv[2], "%lu", &baud); +#else sscanf(argv[2], "%lu", &baud); +#endif // port, baudrate, timeout in milliseconds serial::Serial my_serial(port, baud, serial::Timeout::simpleTimeout(1000)); diff --git a/include/serial/serial.h b/include/serial/serial.h index f7e1fa4..63ae92a 100644 --- a/include/serial/serial.h +++ b/include/serial/serial.h @@ -599,8 +599,7 @@ public: private: // Disable copy constructors Serial(const Serial&); - void operator=(const Serial&); - const Serial& operator=(Serial); + Serial& operator=(const Serial&); std::string read_cache_; //!< Cache for doing reads in chunks. @@ -624,8 +623,7 @@ private: class SerialException : public std::exception { // Disable copy constructors - void operator=(const SerialException&); - const SerialException& operator=(SerialException); + SerialException& operator=(const SerialException&); std::string e_what_; public: SerialException (const char *description) { @@ -645,8 +643,7 @@ public: class IOException : public std::exception { // Disable copy constructors - void operator=(const IOException&); - const IOException& operator=(IOException); + IOException& operator=(const IOException&); std::string file_; int line_; std::string e_what_; @@ -655,7 +652,13 @@ public: explicit IOException (std::string file, int line, int errnum) : file_(file), line_(line), errno_(errnum) { std::stringstream ss; - ss << "IO Exception (" << errno_ << "): " << strerror (errnum); + char error_str [1024]; +#ifdef WIN32 + strerror_s(error_str, 1024, errnum); +#else + error_str = strerror(errnum); +#endif + ss << "IO Exception (" << errno_ << "): " << error_str; ss << ", file " << file_ << ", line " << line_ << "."; e_what_ = ss.str(); } @@ -681,7 +684,6 @@ public: class PortNotOpenedException : public std::exception { // Disable copy constructors - void operator=(const PortNotOpenedException&); const PortNotOpenedException& operator=(PortNotOpenedException); std::string e_what_; public: diff --git a/src/impl/win.cc b/src/impl/win.cc index 1eeea2d..a17b83e 100644 --- a/src/impl/win.cc +++ b/src/impl/win.cc @@ -49,13 +49,13 @@ Serial::SerialImpl::open () } LPCWSTR lp_port = port_.c_str(); - fd_ = CreateFile(lp_port, - GENERIC_READ | GENERIC_WRITE, - 0, - 0, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - 0); + fd_ = CreateFileW(lp_port, + GENERIC_READ | GENERIC_WRITE, + 0, + 0, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + 0); if (fd_ == INVALID_HANDLE_VALUE) { DWORD errno_ = GetLastError(); @@ -508,7 +508,7 @@ Serial::SerialImpl::getCTS () THROW (IOException, "Error getting the status of the CTS line."); } - return (bool) (MS_CTS_ON & dwModemStatus); + return (MS_CTS_ON & dwModemStatus) != 0; } bool @@ -522,7 +522,7 @@ Serial::SerialImpl::getDSR () THROW (IOException, "Error getting the status of the DSR line."); } - return (bool) (MS_DSR_ON & dwModemStatus); + return (MS_DSR_ON & dwModemStatus) != 0; } bool @@ -536,7 +536,7 @@ Serial::SerialImpl::getRI() THROW (IOException, "Error getting the status of the RI line."); } - return (bool) (MS_RING_ON & dwModemStatus); + return (MS_RING_ON & dwModemStatus) != 0; } bool @@ -551,7 +551,7 @@ Serial::SerialImpl::getCD() THROW (IOException, "Error getting the status of the CD line."); } - return (bool) (MS_RLSD_ON & dwModemStatus); + return (MS_RLSD_ON & dwModemStatus) != 0; } void diff --git a/src/serial.cc b/src/serial.cc index 9114166..a247841 100755 --- a/src/serial.cc +++ b/src/serial.cc @@ -37,7 +37,6 @@ public: private: // Disable copy constructors ScopedReadLock(const ScopedReadLock&); - void operator=(const ScopedReadLock&); const ScopedReadLock& operator=(ScopedReadLock); SerialImpl *pimpl_; @@ -54,7 +53,6 @@ public: private: // Disable copy constructors ScopedWriteLock(const ScopedWriteLock&); - void operator=(const ScopedWriteLock&); const ScopedWriteLock& operator=(ScopedWriteLock); SerialImpl *pimpl_; };