## The PIOFAKE Sample

The PIOFAKE Sample accompanies Chapter 14 and illustrates how to program a simple programmed I/O device and how to use a watchdog timer.

The sample includes two components:

- PIOFAKE.SYS (SYS subdirectory) is a WDM driver for a non-existent hardware device.
- TEST.EXE (TEST subdirectory) is a user-mode test program that tries to write data to the PIOFAKE device.

### Building PIOFAKE

To build PIOFAKE.SYS, follow the general instructions for building a WDM sample. The Microsoft Visual C++ project file is named PIOFAKE.DSP in the SYS subdirectory.

To build TEST.EXE, follow the general instructions for building user-mode programs. The Microsoft Visual C++ project file is named TEST.DSP in the TEST subdirectory.

### Testing PIOFAKE

Install the PIOFAKE "device." Follow the general instructions for using FastInst in Windows XP, Xp or Windows 98/Me. Do not use FASTINST in Windows Millennium. For reasons I don't understand, FASTINST precipatates a ring-0 page fault with this one sample only. Use the Add New Hardware wizard from Control Panel instead. The INF file is named SYS\PIOFAKE.INF. Take note of the IRQ and port address that the PnP Manager assigns.

Launch the DEVTEST.EXE program that you'll find in the directory where you installed the book samples (e.g., WDMBOOK). Fill in the port address and IRQ, and then press the Initialize button:

Now open a command prompt and launch TEST.EXE from the TEST\DEBUG subdirectory. The letter "H" should appear in the Device Data control of the DEVTEST dialog. If you press the Interrupt button before 10 seconds elapse, you'll see the second character of the output string TEST is trying to write. You can continue pressing the Interrupt button to see the rest of the message, but you'll be able to guess the contents long before it finishes printing. Delay more than 10 seconds to see the write operation time out.

### What to look for

The file ReadWrite.cpp contains the important subroutines in this sample.