Listing 1 Driver access by applications
void AppDemo()
{
HANDLE hCom;
// Open the serial port ýCOM1:ý. This eventually calls COM_Open().
hCom = CreateFile(
_T(ýCOM1:ý),
GENERIC_READ | GENERIC_WRITE,
0, // Exclusive access
NULL, // No security attributes
OPEN_EXISTING, // Required
0, // No overlapped I/O on CE
NULL); // NULL for com devices
if (hCom == INVALID_HANDLE_VALUE)
return;
// Write some ASCII data by calling WriteFile().
// This eventually calls COM_Write().
PCHAR pszText = ýHello from Windows CEý;
DWORD dwBytesWritten;
if (!WriteFile(hCom, pszText, strlen(pszText), &dwBytesWritten, NULL))
{
CloseHandle(hCom);
return;
}
// Read some data by calling ReadFile().
// This eventually calls COM_Read().
CHAR InBuffer[32];
DWORD dwBytesRead;
if (!ReadFile(hCom, InBuffer, sizeof(InBuffer), &dwBytesRead, NULL))
{
CloseHandle(hCom);
return;
}
// Close the handle. This eventually calls COM_Close().
CloseHandle(hCom);
}
|