опубликован 21-10-2001 19:24 MSK
bool bResult;
char inBuffer[256];
int nBytesToRead;
unsigned long nBytesRead;
int dwError;
AnsiString ComAnsver, ComAnsverString;
bool isPrint;// attempt an asynchronous read operation
BOOL fReadStat ;
COMSTAT ComStat ;
DWORD dwErrorFlags, dwLength ;
int nError, nLength ;
char szError[10] ;
SaveLogo("", "DevRead() - 1");
ClearCommError( m_hCom, &dwErrorFlags, &ComStat ) ;
if (dwErrorFlags > 0)
{
//+++
//ShowMessage("Ошибка установки флагов порта");
}
dwLength = ComStat.cbInQue;
//Нет данных для чтения в порте
if (dwLength < 0)
return false;
strcpy(inBuffer, "");
bResult = ReadFile(m_hCom, &inBuffer, dwLength, &nBytesRead, &READ_COM);
//==============================================================================
// if there was a problem, or the async. operation's still pending ...
if (!bResult)
{
READ_COM.Offset += nBytesRead;
// deal with the error code
switch (dwError = GetLastError())
{
case ERROR_HANDLE_EOF:
{
MessageBox(NULL, "Ошибка. Порт закрыт или занят другим приложением.",
"Information", MB_OK|MB_ICONINFORMATION);
//- Попытка открытьпорт
}
case ERROR_IO_PENDING:
{
// asynchronous i/o is still in progress
MessageBox(NULL, "Ошибка. Порт занят.",
"Information", MB_OK|MB_ICONINFORMATION);
return false;
// check on the results of the asynchronous read
bResult = GetOverlappedResult(m_hCom, &READ_COM,
&nBytesRead, FALSE) ;
// if there was a problem ...
if (!bResult)
{
// deal with the error code
switch (dwError = GetLastError())
{
case ERROR_HANDLE_EOF:
{
// we're reached the end of the file
//during asynchronous operation
MessageBox(NULL, "Ошибка. Ошибка. Порт закрыт или занят другим приложением.",
"Information", MB_OK|MB_ICONINFORMATION);
return false;
}
// deal with other error cases
MessageBox(NULL, "Ошибка. Некоректное чтение из потока COM порта!",
"Information", MB_OK|MB_ICONINFORMATION);
return false;
}
}
READ_COM.Offset += nBytesRead;
} // end case
// deal with other error cases
MessageBox(NULL, "Ошибка чтения из COM порта!",
"Information", MB_OK|MB_ICONINFORMATION);
return false;
} // end switch
} // end if
SaveLogo("", "DevRead() - 2");
READ_COM.Offset += nBytesRead - 1;
ComAnsver = inBuffer;
if(ComAnsver.Length() > nBytesRead)
{
ComAnsver.Delete(nBytesRead + 1, ComAnsver.Length() - nBytesRead + 1);
}
LogosMemo->Lines->SetText((LogosMemo->Lines->GetText() + ComAnsver).c_str());
Analis();
return true;
Обрабатываю то что лежит в LogosMemo