X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fplatform%2Fwindows%2Fserialport.cpp;h=8e513fc7f1c6c87f607603786a16ddbf79552090;hb=d0a712a65c05b4bf7bf25eafb8b4c999b6888a42;hp=b028ff32e5e8810f5bb01bcb70cf8aa2810722db;hpb=722869e27e6f6ef9db09fa9114994e167b7e8894;p=deb_libcec.git diff --git a/src/lib/platform/windows/serialport.cpp b/src/lib/platform/windows/serialport.cpp index b028ff3..8e513fc 100644 --- a/src/lib/platform/windows/serialport.cpp +++ b/src/lib/platform/windows/serialport.cpp @@ -30,12 +30,12 @@ * http://www.pulse-eight.net/ */ -#include "../serialport.h" -#include "../baudrate.h" +#include "../serialport/serialport.h" +#include "../serialport/baudrate.h" #include "../timeutils.h" using namespace std; -using namespace CEC; +using namespace PLATFORM; void FormatWindowsError(int iErrorCode, string &strMessage) { @@ -65,8 +65,9 @@ CSerialPort::~CSerialPort(void) bool CSerialPort::Open(string name, uint32_t baudrate, uint8_t databits, uint8_t stopbits, uint8_t parity) { - CLockObject lock(&m_mutex); - m_handle = CreateFile(name.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + CStdString strComPath = "\\\\.\\" + name; + CLockObject lock(m_mutex); + m_handle = CreateFile(strComPath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (m_handle == INVALID_HANDLE_VALUE) { m_error = "Unable to open COM port"; @@ -77,7 +78,7 @@ bool CSerialPort::Open(string name, uint32_t baudrate, uint8_t databits, uint8_t COMMCONFIG commConfig = {0}; DWORD dwSize = sizeof(commConfig); commConfig.dwSize = dwSize; - if (GetDefaultCommConfig(name.c_str(), &commConfig,&dwSize)) + if (GetDefaultCommConfig(strComPath.c_str(), &commConfig,&dwSize)) { if (!SetCommConfig(m_handle, &commConfig,dwSize)) { @@ -158,7 +159,7 @@ bool CSerialPort::SetTimeouts(bool bBlocking) void CSerialPort::Close(void) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_bIsOpen) { CloseHandle(m_handle); @@ -166,26 +167,26 @@ void CSerialPort::Close(void) } } -int8_t CSerialPort::Write(CCECAdapterMessagePtr data) +int64_t CSerialPort::Write(uint8_t* data, uint32_t len) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); DWORD iBytesWritten = 0; if (!m_bIsOpen) return -1; - if (!WriteFile(m_handle, data->packet.data, data->size(), &iBytesWritten, NULL)) + if (!WriteFile(m_handle, data, len, &iBytesWritten, NULL)) { m_error = "Error while writing to COM port"; FormatWindowsError(GetLastError(), m_error); return -1; } - return (int8_t)iBytesWritten; + return (int64_t)iBytesWritten; } int32_t CSerialPort::Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs /* = 0 */) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); int32_t iReturn(-1); DWORD iBytesRead = 0; if (m_handle == 0) @@ -255,6 +256,6 @@ bool CSerialPort::SetBaudRate(uint32_t baudrate) bool CSerialPort::IsOpen() { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_bIsOpen; }