Serial thread problems
Here is my serial worker thread:
UINT SerialThread( LPVOID Param ) //Thread to monitor serial activity
{
HWND hDlg = (HWND)Param;
OVERLAPPED ovl = {0};
BYTE chread;
DWORD dwRead;
DWORD dwEventMask;
int i;
if(!SetCommMask(hCom, EV_RXCHAR))
AfxMessageBox("Error setting ComMask");
while(TRUE){
BOOL running = TRUE;
while(running){
if(WaitCommEvent(hCom, &dwEventMask, NULL)){
if (!ReadFile (hCom, &chread, 1, &dwRead, &ovl)){
AfxMessageBox("Error 1 reading comm port");
}
if (chread == 0x10)
running = FALSE;
}
}
for (i=0; i<33; i++){
if(WaitCommEvent(hCom, &dwEventMask, NULL)){
AfxMessageBox("Error 2 reading comm port");
}
if (!ReadFile (hCom, &chread, 1, &dwRead, &ovl)){
AfxMessageBox("Error reading data");
}
Bar[i] = chread;
}
::PostMessage(hDlg, MY_SERIAL, (WPARAM)0, (LPARAM)0);
}
return TRUE;
}
When a 10h is received the thread is supposed to read 33 more bytes to
a unsigned char string in Bar[]
I have verifyied that the 10h is received but I get "Error 2 reading
comm port" 2 times.
Please guide me.