PORTIO

SUMMARY

This generic port I/O device driver sample shows how to reserve I/O ports and read and write to it from an user application.

The driver building and installation instructions given here only apply to Windows® 2000.

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 Developement 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:

  1. Double-click the Add/Remove Hardware Wizard applet in Control Panel.
  2. Select Add/Troubleshoot a Device.
  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.

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 port between 300 and 3fc as specified in the LC1 configuration.

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/ddk/.

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