-bool CSerialPort::SetTimeouts(bool bBlocking)
-{
- if (m_handle == INVALID_HANDLE_VALUE)
- return false;
-
- COMMTIMEOUTS cto;
- if (!GetCommTimeouts(m_handle, &cto))
- {
- m_strError = "GetCommTimeouts failed";
- FormatWindowsError(GetLastError(), m_strError);
- return false;
- }
-
- if (bBlocking)
- {
- cto.ReadIntervalTimeout = 0;
- cto.ReadTotalTimeoutConstant = 0;
- cto.ReadTotalTimeoutMultiplier = 0;
- }
- else
- {
- cto.ReadIntervalTimeout = MAXDWORD;
- cto.ReadTotalTimeoutConstant = 0;
- cto.ReadTotalTimeoutMultiplier = 0;
- }
-
- if (!SetCommTimeouts(m_handle, &cto))
- {
- m_strError = "SetCommTimeouts failed";
- FormatWindowsError(GetLastError(), m_strError);
- return false;
- }
-
- return true;
-}
-
-void CSerialPort::Close(void)
-{
- CLockObject lock(m_mutex);
- if (m_bIsOpen)
- {
- CloseHandle(m_handle);
- m_bIsOpen = false;
- }
-}
-
-int64_t CSerialPort::Write(uint8_t* data, uint32_t len)
-{
- CLockObject lock(m_mutex);
- DWORD iBytesWritten = 0;
- if (!m_bIsOpen)
- return -1;
-
- if (!WriteFile(m_handle, data, len, &iBytesWritten, NULL))
- {
- m_strError = "Error while writing to COM port";
- FormatWindowsError(GetLastError(), m_strError);
- return -1;
- }
-
- return (int64_t)iBytesWritten;
-}
-
-int32_t CSerialPort::Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs /* = 0 */)
-{
- CLockObject lock(m_mutex);
- int32_t iReturn(-1);
- DWORD iBytesRead = 0;
- if (m_handle == 0)
- {
- m_strError = "Error while reading from COM port: invalid handle";
- return iReturn;
- }
-
- if(!ReadFile(m_handle, data, len, &iBytesRead, NULL) != 0)
- {
- m_strError = "unable to read from device";
- FormatWindowsError(GetLastError(), m_strError);
- iReturn = -1;
- }
- else
- {
- iReturn = (int32_t) iBytesRead;
- }
-
- return iReturn;
-}
-
-bool CSerialPort::SetBaudRate(uint32_t baudrate)