/* Serial Mouse Tester Copyright (C) 2000-2007 Dmitry Brant http://dmitrybrant.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ //--------------------------------------------------------------------------- #include #pragma hdrstop #include "BkgThread.h" #include "main.h" #pragma package(smart_init) //--------------------------------------------------------------------------- __fastcall ComThread::ComThread() : TThread(false){ Priority = tpLower; FreeOnTerminate = false; // Don't automatically delete ourselves when terminated. } //--------------------------------------------------------------------------- void __fastcall ComThread::Execute(){ DWORD dwErrors; COMSTAT cst; DWORD NumberOfBytesRead, message, fdwAction; HANDLE WinComHandle = MainForm->comHandle; HWND hwnd = (HWND)MainForm->Handle; int ptr=0; char comchar; ClearCommError(WinComHandle, (LPDWORD)&dwErrors, (LPCOMSTAT)&cst); switch (dwErrors){ case 0: case CE_BREAK: break; default: return; }; while(!Terminated){ ClearCommError(WinComHandle, (LPDWORD)&dwErrors, (LPCOMSTAT)&cst); if(cst.cbInQue >= 3){ if(!ReadFile(WinComHandle, (LPVOID)&message, 3, (LPDWORD)&NumberOfBytesRead, NULL)){ return; } if(!NumberOfBytesRead){ }else if((NumberOfBytesRead > 0) && (NumberOfBytesRead < 3)){ }else if(!(((unsigned char*)&message)[0] & 64)){ fdwAction = PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR; PurgeComm(WinComHandle, fdwAction); }else{ PostMessage(hwnd, MY_MESSAGE, (WPARAM)message, NULL); ptr = 0; message = 0; } } } } //------------------------------