X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fplatform%2Fwindows%2Fserialport.cpp;h=c595468cf0b5621d3efc7de3a39bd521a03138f2;hb=34a9cecdd92f6b2844f9c4054da202b152ab2217;hp=96e743f80e0759fba864a6fa9ad171128a0bd850;hpb=1bede530033f40a81400c7a1e4ed0e8755d4ec59;p=deb_libcec.git diff --git a/src/lib/platform/windows/serialport.cpp b/src/lib/platform/windows/serialport.cpp index 96e743f..c595468 100644 --- a/src/lib/platform/windows/serialport.cpp +++ b/src/lib/platform/windows/serialport.cpp @@ -30,14 +30,15 @@ * http://www.pulse-eight.net/ */ -#include "../sockets/serialport.h" -#include "../util/baudrate.h" -#include "../util/timeutils.h" +#include "env.h" +#include "lib/platform/sockets/serialport.h" +#include "lib/platform/util/baudrate.h" +#include "lib/platform/util/timeutils.h" using namespace std; using namespace PLATFORM; -void FormatWindowsError(int iErrorCode, CStdString &strMessage) +void FormatWindowsError(int iErrorCode, std::string &strMessage) { if (iErrorCode != ERROR_SUCCESS) { @@ -99,7 +100,17 @@ void CSerialSocket::Shutdown(void) ssize_t CSerialSocket::Write(void* data, size_t len) { - return IsOpen() ? SerialSocketWrite(m_socket, &m_iError, data, len) : -1; + if (IsOpen()) + { + ssize_t iReturn = SerialSocketWrite(m_socket, &m_iError, data, len); + if (iReturn != len) + { + m_strError = "unable to write to the serial port"; + FormatWindowsError(GetLastError(), m_strError); + } + return iReturn; + } + return -1; } ssize_t CSerialSocket::Read(void* data, size_t len, uint64_t iTimeoutMs /* = 0 */) @@ -119,7 +130,7 @@ bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */) if (IsOpen()) return false; - CStdString strComPath = "\\\\.\\" + m_strName; + std::string strComPath = "\\\\.\\" + m_strName; CLockObject lock(m_mutex); m_socket = CreateFile(strComPath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (m_socket == INVALID_HANDLE_VALUE) @@ -168,6 +179,7 @@ bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */) return false; } + m_strError.clear(); m_bIsOpen = true; return m_bIsOpen; }