Serial thread continued
I have managed to make some headway on the serial thread.
I have a button on my dialog that sends a byte to a microcontroller.
The micro responds by sending a 10h followed by 33 bytes.
I have tested the micro's response with hyperterm so I know it works.
Now when the 10h comes in it does seem to read the 33 bytes that
follow'd.
BUT, before the PostMessage I get the error "Error reading data".
When I click OK on the error messagebox all the data did appear as
expected.
How do I find out what the error was?
Also after the data appears another MessageBox show "Error 1 reading
port".
This is appearing after the data shows and no more requests are made
for more.
Below is the current routine.
Please just fix it or explain how to fix it clearly.
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");
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){
for (i=0; i<33; i++){
if (!ReadFile (hCom, &chread, 1, &dwRead, &ovl)){
AfxMessageBox("Error reading data");
}
Bar[i] = chread;
}
::PostMessage(hDlg, MY_SERIAL, (WPARAM)0, (LPARAM)0);
}
}
}
return TRUE;
}