3 #include <winpr/comm.h>
4 #include <winpr/file.h>
5 #include <winpr/synch.h>
6 #include <winpr/handle.h>
8 int TestCommMonitor(
int argc,
char* argv[])
15 LPCSTR lpFileName =
"\\\\.\\COM1";
17 hComm = CreateFileA(lpFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
18 FILE_FLAG_OVERLAPPED, NULL);
20 if (!hComm || (hComm == INVALID_HANDLE_VALUE))
22 printf(
"CreateFileA failure: %s\n", lpFileName);
26 fSuccess = SetCommMask(hComm, EV_CTS | EV_DSR);
30 printf(
"SetCommMask failure: GetLastError() = %" PRIu32
"\n", GetLastError());
34 if (!(overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
36 printf(
"CreateEvent failed: GetLastError() = %" PRIu32
"\n", GetLastError());
40 if (WaitCommEvent(hComm, &dwEvtMask, &overlapped))
42 if (dwEvtMask & EV_DSR)
47 if (dwEvtMask & EV_CTS)
54 dwError = GetLastError();
56 if (dwError == ERROR_IO_PENDING)
58 printf(
"ERROR_IO_PENDING\n");
62 printf(
"WaitCommEvent failure: GetLastError() = %" PRIu32
"\n", dwError);
67 (void)CloseHandle(hComm);