Книга: Writing Windows WDM Device Drivers

Testing WdmIo

Testing WdmIo

Installing WdmIo

Installing a WdmIo device for a parallel port is a bit trickier than all the previous drivers. This is because Windows should already have installed its own driver to service the port. It is possible to run WdmIo for a parallel port in Windows 98. However, I found it was not possible in Windows 2000. The PHDIo driver can be forced to run in W2000 to talk to a parallel port.

The WdmIoLpt1Checked.inf and WdmIoLpt1Free.inf installation files are designed for a parallel port that, by default, lives at address 0x0378 and generates ISA interrupt IRQ7. Other configurations are made available for the user to select.

The best way to install WdmIo in Windows 98 is to use Hardware profiles. A Hardware profile is the combination of drivers that Windows loads. The trick is to have one profile in which the standard Windows parallel port driver is available. Another Hardware profile loads the WdmIo driver. When Windows starts, select the profile that you want to use.

In the Control Panel System applet, select the Hardware profiles tab. Copy the "Original Configuration" profile into a new profile called "WdmIo". Reboot into this new profile. In the Device Manager, select the Parallel port (LPT1) driver. First, remember which resources the LPT1 driver uses. Now remove the Parallel port driver from this profile. Simply disabling the driver is not good enough, as a disabled driver still keeps its resource assignments. Do not restart yet.

Now install a WdmIo device in the Other devices category as usual. You will have to reboot for the WdmIo device to be activated. I found that removing the Parallel port driver may mean that the parallel port was disabled in the BIOS setup. As you do the last reboot, you should go into your BIOS setup and reenable the LPT1 port again.

If you ever reboot and choose the "Original Configuration" hardware profile, you will find that the WdmIo device has been removed from the WdmIo profile. You will have to reinstall it and reboot. Sigh.

If you use WdmIo to talk to some of your own custom hardware, you will almost certainly not need to go through all of the previous shenanigans. Similarly, for a one off test of WdmIo talking to a parallel port, you should be able to install it without using different hardware profiles.

In Windows 2000 beta 2, I found that it was impossible to install a WdmIo device in place of the standard parallel port driver. If a parallel port driver was removed to make the resources available, Windows 2000 always reinstalled the driver on reboot before the WdmIo device could be loaded.

LogConfig Sections

The WdmIo INF files must be set up for each device to which it will talk. A LogConfig section or sections must be added to give the resource assignments. Listing 15.5 shows the amendments that have been made to the WdmIoLpt1Checked.inf and WdmIoLpt1Free.inf installation files.

Both the Windows 98 WdmIo.Install and the Windows 2000 WdmIo.Install .NTx86 sections have a LogConfig directive that refers to the three LogConfig sections, each of which have different possible resource assignments. These eventually appear to users in the Device properties Resources tab as "Basic configuration 0", "Basic configuration 1", and "Basic configuration 2". Each section has a configuration priority. WdmIo.LogConfig1 has priority DESIRED that is higher than the NORMAL priority of the other LogConfig sections.

The WdmIo. LogConfig1 resource assignments are chosen by preference. There is only one I/O port range, 0x378 to 0x37A, so this address range is used. However, two IRQ numbers are listed, 5 and 7. Only one of these is used. In some computers, IRQ5 will already be used, so IRQ7 will be selected automatically. If both IRQs are available, the user will be prompted to make a choice.

The user, therefore, has to confirm which resource assignments to make. For the WdmIo device, Windows does not detect the parallel port and load the appropriate drivers. It is up to the device installer to select the correct resource assignments. The WdmIo driver does not care which port address or IRQ it is assigned. To do a useful job, the resources must correspond to a real device, and the controlling Win32 application must use the registers and interrupts in the correct way.

If you try to install a second WdmIo device for a parallel port, Windows should choose one of the remaining configurations. Windows 98 displays the chosen resource assignments and asks the user to confirm that these are satisfactory. It then tells you to insert the card. If the system's resource assignments have to be juggled to accommodate the new device, you may have to reboot.

Listing 15.5 WdmIoLpt1Xxx.INF LogConfig sections

[WdmIo.Install]
CopyFiles=WdmIo.Files.Driver
AddReg=WdmIo.AddReg
LogConfig=WdmlIo.LogConfig1,WdmIo.LogConfig2,WdmIo.LogConfig3
[WdmIo.LogConfig1]
ConfigPriority=DESIRED
IOConfig=378-37a
IRQConfig=7,5
[WdmIo.LogConfig2]
ConfigPriority=NORMAL
IOConfig=278-27a
IRQConfig=7,5
[WdmIo.LogConfig3]
ConfigPriority=NORMAL
IOConfig=3bc-3be
IRQConfig=7,5
[WdmIo.Install.NTx86]
CopyFiles=WdmIo.Files.Driver.NTx86
LogConfig=WdmIo.LogConfig1.WdmIo.LogConfig2,WdmIo.LogConfig3

A large number of entries can be put in Logconfig sections. For a start, further IOConfig and IRQConfig entries can be given if a device can have more than one of these resources simultaneously. The IOConfig and IRQConfig entries can be specified in a variety of ways. DMAConfig, PcCardConfig, MemConfig, and MfCardConfig entries can also be included. I found that the Windows 2000 DDK was the best source of information on all these entries.

Running WdmIoTest

With a WdmIo device finally installed for one of your parallel ports, it is now possible to run the WdmIoTest program. Do not forget to plug in a printer. I found that a clattery old dot matrix printer was best for testing, as it produced audible output straightaway. With a page-oriented ink jet or laser printer, you might have to press Formfeed to see the printed information.

When you run WdmIoTest, the printer should initialize itself and print out a two-line short message.

If the printer is switched off, WdmIoTest will keep checking to see if it is ready for 20 seconds. It will give up if it is not available by then. To test the time-out behavior of WriteFile, you must comment out the busy check code. If you now run WdmIoTest again, it will attempt to write information to the printer. It should time-out after 10 seconds with error 21 (ERROR_ NOT_READY).

The WdmIo driver handles the user pressing Ctrl+C correctly. I shall show in the next chapter how this IRP cancelling and cleanup occurs.

Оглавление книги


Генерация: 2.137. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз