Tidied a bit
@@ -70,6 +70,7 @@ void CloseCom()
CloseHandle(osRX.hEvent);
CloseHandle(osTX.hEvent);
CloseHandle(hComm);
+ hComm = INVALID_HANDLE_VALUE;
}
bool OpenComPort(const char *pszComPort, bool bTestConnection = false)
@@ -92,9 +93,7 @@ bool OpenComPort(const char *pszComPort, bool bTestConnection = false)
uint32_t WriteCom(char *pBuffer, uint32_t uLen)
{
DWORD dwWritten = 0;
- auto write = WriteFile(hComm, pBuffer, uLen, NULL, &osTX);
- auto err = GetLastError();
- if (!write && err == ERROR_IO_PENDING)
+ if (!WriteFile(hComm, pBuffer, uLen, NULL, &osTX) && GetLastError() == ERROR_IO_PENDING)
GetOverlappedResult(hComm, &osTX, &dwWritten, TRUE);
return dwWritten;
}
