PORTIO

SUMMARY

This generic port I/O device driver sample shows how to reserve I/O ports for a non plug-n-play device with an INF file, and read and write to it from an user application.

The driver building and installation instructions given here applies to Windows® 2000, XP, and Server 2003.

Note: This sample provides an example of a minimal driver. Neither it nor its sample programs are intended for use in a production environment. Rather, they are intended for educational purposes and as a skeleton driver.

BUILDING THE SAMPLE

Click the Free Build Environment or Checked Build Environment icon under your Development Kits program group to set basic environment variables needed by the build utility.

Change to the directory containing the device source code, such as CD Src\General\Portio.

Run build -ceZ, or use the macro BLD. This behavior invokes the Microsoft make routines that produce log files called Buildxxx.log, and also Buildxxx.wrn and Buildxxx.err if there are any warnings or errors. Where xxx stands for fre or chk depending on the environment chosen. If the build succeeds, the driver Genport.sys and two application GpdRead.exe and GpdWrite will be placed in a platform specific subdirectory of your %TargetPath% directory specified in the Sources file.

Driver Installation

To install the driver on Windows 2000:

  1. Double-click the Add New Hardware Wizard applet in Control Panel.
  2. Click Next.
  3. Select Add a new device.
  4. Select No, I Want to Select the Hardware from a list.
  5. Select Other Devices and then click Next.
  6. Click Have Disk and point to the directory that contains genport.inf file. Make sure the SYS file is copied under appropriate subdirectory (i386, ia64, amd64).
To install the driver on Windows XP and Windows Server 2003:

  1. Double-click the ‘Add Hardware’ wizard in Control Panel.
  2. At the 'Welcome to the Add Hardware Wizard', click ‘Next’.
  3. Select 'Yes, I have already connected the hardware', then click Next.
  4. Select ‘Add a new hardware device’ from the list, then click Next.
  5. Select ‘Install the hardware that I manually select from a list(Advanced),' and then click next.
  6. Select ‘Show All Devices’, then click Next.
  7. Click 'Have Disk', make sure that 'A:\' is in the "Copy manufacturer's files from:" box, and click OK.
  8. Click on the desired entry, and then click Next.
  9. At 'The wizard is ready to install your hardware', click Next.
  10. Click Finish at 'Completing the Add/Remove Hardware Wizard.'

Alternatively, you can use the DEVCON.EXE from the DDK to install the driver programmatically.

c:\>DEVCON.EXE INSTALL genport.inf "root\portio"

The system copies the genport.sys file to %systemroot%\system32\drivers directory and loads the driver. The INF file specifies two logical configuartion for the device.


[PortIO.LC0]
ConfigPriority=DESIRED
IOConfig=300-303(3ff::) ; 10 bit decode ranging from 300 - 303

[PortIO.LC1]
ConfigPriority=NORMAL
IOConfig=4@300-3ff(3ff::) ; 4 ports starting anywhere between 300 and 3fc

The system will first try to assing the DESIRED configuration. If there is conflict then it will try to assign any 4 consecutive ports between 300 and 3fc as specified in the LC1 configuration. Please note that priorities "NORMAL", "DESIRED", and "SUBOPTIMAL" imply that the device can be software reconfigured and so will accept the factory defaults. "HARDRECONFIG" means that the user has to manually change the jumper settings on the board, so the system will prompt user to select the resources during install.

TOOLS

To test your GENPORT driver, do the following.

GpdRead -b 1 {This reads a byte from assingned 'base port address + 1' }

GpdWrite -b 2 1 {This writes 1 to assigned 'base port address + 2' }

RESOURCES

For the latest release of the Windows NT device driver kit, see http://www.microsoft.com/whdc/devtools/ddk.

For information about driver and hardware development, see http://www.microsoft.com/whdc.

CODE TOUR

File Manifest

File		Description

Portio.htm	Sample Tour documentation for this sample (this file).
Sources		Generic file for building the code sample.
genport.inf	File for installing the driver.
Gpioctl.h	Include file for defining IOCTL codes used by driver and test applications.
Gpdread.c	Source file that shows how to read a byte from a port using the genport driver.
Gpdwrite.c	Source file that shows how to write a byte to a port using the genport driver.
Genport.h	Include file for Generic Port I/O Driver.
Genport.c	Source file for Generic Port I/O Driver.

Top of page

© 1998 Microsoft Corporation