Portbase User Guide
SetCommState(hComm, &dcb);
// Sets a timer for transmission.
SetTimer(1, 3000, NULL);
// Sets a timer for reception.
SetTimer(2, 1, NULL);
}
void CExample1Dlg::OnTimer(UINT nIDEvent)
{
CEdit * pEdt = (CEdit *)GetDlgItem(IDC_edtWINDOW);
char WriteData[30] = "This is LoopBack Data !";
DWORD Writed;
if(nIDEvent == 1) { // In case data is output to the port.
// Outputs data to the port.
WriteFile(hComm, WriteData, strlen(WriteData), &Writed, NULL);
}
if(nIDEvent == 2) { // In case data is inputted to the port.
COMSTAT c;
char rbuff[1000];
DWORD nBytesRead = 0, Error;
// Clears an error & obtains the length of data to be read.
ClearCommError(hComm, &Error, &c);
if(c.cbInQue) {
ReadFile(hComm, rbuff, c.cbInQue, &nBytesRead, NULL);
// Outputs data to the edit box.
rbuff[nBytesRead] = 0;
pEdt->ReplaceSel(rbuff);
}
}
}
104