|
@@ -112,7 +112,6 @@ void CSerialPort::Open(LPCTSTR pszPort, /* COM1 */
|
|
|
BOOL bOverlapped /* = 0 */)
|
|
|
{
|
|
|
Close(); // In case we are already open
|
|
|
-
|
|
|
// Call CreateFile to open the comms port
|
|
|
TCHAR szPort[10] = {0};
|
|
|
_stprintf_s(szPort, _T("\\\\.\\%s"), pszPort);
|
|
@@ -120,26 +119,29 @@ void CSerialPort::Open(LPCTSTR pszPort, /* COM1 */
|
|
|
if(m_hComm == INVALID_HANDLE_VALUE)
|
|
|
{
|
|
|
DWORD dwLastError = GetLastError();
|
|
|
- //TRACE(_T("CSerialPort::Open, Failed to open the comms port, Error:%d\n"), dwLastError);
|
|
|
LOG4C((LOG_WARN,"%s´ò¿ªÊ§°Ü£¬GetLastError=%ld", szPort, dwLastError));
|
|
|
- //ThrowSerialException(dwLastError);
|
|
|
+ Global::WriteReportLog(1, "Serial port error", "Open Serial Port Fail, GetLastError=%ld !", dwLastError);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
// Create the event we need for later synchronisation use
|
|
|
m_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
|
if(m_hEvent == NULL)
|
|
|
{
|
|
|
- DWORD dwLastError = GetLastError();
|
|
|
- Close();
|
|
|
- //TRACE(_T("CSerialPort::Open, Failed in call to CreateEvent in Open, Error:%d\n"), dwLastError);
|
|
|
+ DWORD dwLastError = GetLastError();
|
|
|
LOG4C((LOG_WARN,"CreateEventʧ°Ü£¬GetLastError=%ld", szPort, dwLastError));
|
|
|
- //ThrowSerialException(dwLastError);
|
|
|
+ Global::WriteReportLog(1, "Serial port error", "CreateEvent Fail, GetLastError=%ld !", dwLastError);
|
|
|
+ Close();
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
if ( !SetupComm(m_hComm,10240,2048) )
|
|
|
{
|
|
|
+ DWORD dwLastError = GetLastError();
|
|
|
CloseHandle(m_hComm);
|
|
|
CloseHandle(m_hEvent);
|
|
|
+ Global::WriteReportLog(1, "Serial port error", "SetupComm Fail, GetLastError=%ld !", dwLastError);
|
|
|
+ Close();
|
|
|
return ;
|
|
|
}
|
|
|
// Get the current state prior to changing it
|