Click to See Complete Forum and Search --> : serial communication


Patrick Siu
April 21st, 1999, 09:20 PM
I am trying to write a program that can auto detect a singal coming in from serial communication. For example, if there is any signal change for serial port pin 6 DSR. My program will pop up a message box.
Following is my code but not working

void CAutodetDlg::OnDetectButton()
{
// TODO: Add your control notification handler code here
HANDLE hfile;
//DWORD dwEvtMask;
DWORD dwStoredFlags;
dwStoredFlags = EV_BREAK| EV_CTS| EV_DSR| EV_ERR| EV_RING|
EV_RLSD| EV_RXCHAR| EV_RXFLAG| EV_TXEMPTY;
char* pszfilename = "COM1";
hfile = CreateFile(pszfilename,
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
NULL,
NULL);
if (hfile == INVALID_HANDLE_VALUE)
{
MessageBox("COM not ready");
}

if (!SetCommMask(hfile, dwStoredFlags))
{
MessageBox("SetCommMask Error");
}
MessageBox("SetCommMask Pass");
if (!WaitCommEvent(hfile, &dwStoredFlags, NULL))
{
MessageBox("Pending");
}
else
MessageBox("DSR changed");

}