more CommEvents than expected
- From: "Tony" <tgperfcodn@xxxxxxxxxxxxxxxx>
- Date: Sun, 18 Jun 2006 04:05:31 GMT
I am receiving a lot more events from WaitCommEvent() than I expect. I think
there should be only five lines of output for status changes with COM1 inputs
as follows:
DSR pin 6 is always true
RING pin 9 goes true
CTS pin 8 goes true for only 1.5 seconds
RING pin 9 goes false
DSR pin 6 is stays true
I get some repeated lines in the following output
commStatus = 20 (okay, pin 6 was high)
ev_ring pin nine fPending = 0 commStatus = 60 (okay, pin 9 went high)
ev_ring pin nine fPending = 0 commStatus = 60 (why)
ev_cts pin eight fPending = 0 commStatus = 60 (why)
ev_cts pin eight fPending = 0 commStatus = 60 (why)
ev_cts pin eight fPending = 0 commStatus = 60 (why)
ev_cts pin eight fPending = 0 commStatus = 70 (okay, pin 8 went high)
ev_cts pin eight fPending = 0 commStatus = 70 (why)
ev_cts pin eight fPending = 0 commStatus = 70 (why)
ev_cts pin eight fPending = 0 commStatus = 70 (why)
ev_cts pin eight fPending = 0 commStatus = 60 (okay, pin 8 went low)
ev_cts pin eight fPending = 0 commStatus = 60 (why)
ev_cts pin eight fPending = 0 commStatus = 60 (why)
ev_cts pin eight fPending = 0 commStatus = 60 (why)
ev_cts pin eight fPending = 0 commStatus = 60 (why)
ev_cts pin eight fPending = 0 commStatus = 60 (why)
ev_ring pin nine fPending = 0 commStatus = 20 (okay, pin 9 went low)
The lines marked (why) seem strange to me. What are these state changes?
Note: the WaitCommEvent is always finishing and returning no error on the
first call. This may be okay.
Note: The TX and RX lines are not connected. We are using the COM1 port as
input for a few discrete signals.
Note: Pin 4 is jumpered to Pin 6 to signal the cable is connected.
Note: The operating system is Windows XP Professional
// Here is my code
#include <windows.h>
#include <stdio.h>
#include <conio.h>
HANDLE g_hEvStop;
DWORD WINAPI ThreadProcSS(LPVOID lpvParam)
{
HANDLE hCom;
DWORD dwEvtMask = 0;
OVERLAPPED o;
BOOL fPending = 0;
DWORD dwRet;
HANDLE hArray[2];
BOOL proc;
DWORD dwCommStatus;
memset(&o, 0, sizeof(o));
o.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (o.hEvent == NULL)
{
printf("CreateEvent failed.\n");
return 1;
}
hCom = CreateFile("\\\\.\\COM1",
GENERIC_READ | GENERIC_WRITE,
0, // exclusive access
NULL, // no security attrs
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
if (hCom == INVALID_HANDLE_VALUE)
{
printf("unable to open COM port\n");
CloseHandle(o.hEvent);
return 1;
}
if (GetCommModemStatus(hCom, &dwCommStatus))
printf("commStatus = %x\n", dwCommStatus);
else
printf("Error = %d\n", GetLastError());
SetCommMask(hCom, EV_CTS | EV_DSR | EV_RING | EV_RLSD );
hArray[0] = g_hEvStop;
hArray[1] = o.hEvent;
for(;;)
{
proc = 0;
if (!fPending)
{
if (WaitCommEvent(hCom, &dwEvtMask, &o))
{
proc = 1;
}
else
{
if (GetLastError() == ERROR_IO_PENDING)
{
fPending = 1;
}
}
}
else
{
dwRet = WaitForMultipleObjects(2, hArray, FALSE, INFINITE);
if (dwRet == WAIT_OBJECT_0)
{
break;
}
if (dwRet == WAIT_OBJECT_0 + 1)
{
proc = 1;
fPending = 0;
}
}
if (proc)
{
if (dwEvtMask & EV_DSR) printf("ev_dsr pin six fPending = %d ",
fPending);
if (dwEvtMask & EV_CTS) printf("ev_cts pin eight fPending = %d ",
fPending);
if (dwEvtMask & EV_RING) printf("ev_ring pin nine fPending = %d ",
fPending);
if (dwEvtMask & EV_RLSD) printf("ev_rlsd pin one fPending = %d ",
fPending);
if (GetCommModemStatus(hCom, &dwCommStatus))
printf("commStatus = %x\n", dwCommStatus);
else
printf("Error = %d\n", GetLastError());
}
}
CloseHandle(o.hEvent);
CloseHandle(hCom);
return 0;
}
DWORD WINAPI ThreadProcKB(LPVOID lpvParam)
{
int ch;
for(;;)
{
if (kbhit())
{
ch = getch();
if (ch == 0)
ch = getch();
if (ch == 'n')
printf("-------\n");
else
{
SetEvent(g_hEvStop);
break;
}
}
else
{
Sleep(10);
}
}
return 0;
}
int main(void)
{
HANDLE hThreadKB;
HANDLE hThreadSS;
DWORD dwThreadIDKB;
DWORD dwThreadIDSS;
HANDLE hArray[2];
g_hEvStop = CreateEvent(NULL,TRUE,FALSE,NULL);
hThreadKB = CreateThread(NULL, 0, ThreadProcKB, 0, 0, &dwThreadIDKB);
hThreadSS = CreateThread(NULL, 0, ThreadProcSS, 0, 0, &dwThreadIDSS);
hArray[0] = hThreadKB;
hArray[1] = hThreadSS;
WaitForMultipleObjects(2, hArray, FALSE, INFINITE);
CloseHandle(g_hEvStop);
CloseHandle(hThreadKB);
CloseHandle(hThreadSS);
return 0;
}
.
- Follow-Ups:
- Re: more CommEvents than expected
- From: Joe Hagen
- RE: more CommEvents than expected
- From: Rhett Gong [MSFT]
- Re: more CommEvents than expected
- Prev by Date: Re: Threading Delay
- Next by Date: Re: NetShareAdd() In Kernel Mode
- Previous by thread: Re: Threading Delay
- Next by thread: RE: more CommEvents than expected
- Index(es):
Relevant Pages
|