Direct I/O Access from Win32 User Mode Applications to PC Parallel Port(s) under Microsoft Windows NT 4.0 |
Overview | The Parallel
Port Direct I/O Access package delivers the ability to access PC parallel ports from Win32
applications under Microsoft Windows NT 4.0. Previously, the only way would have been to
write an NT device driver to perform the I/O on behalf of the application. This kernel mode driver and Win32 library combination allow Win32 applications to execute IN and OUT instructions to the parallel port device hardware I/O ports. Access is coordinated with the standard NT parallel driver to ensure that the parallel port is only 'claimed' if no other process is currently using it. Once the port is 'claimed', other processes are blocked from using the port (assuming they also use the standard parallel port arbitration scheme). Once the application has finished using the parallel port, it may either exit or call the 'release' API and the parallel port is free for use by any other process again.
|
|||||||||||||||||||||||
How it works | Normally,
under Windows NT, access is not permitted to the I/O port range of the parallel port (and
most others). Executing an IN or OUT instruction causes a privileged instruction exception
resulting in termination of the process. The driver works by changing the I/O permission map (IOPM) for the process that 'claims' the indicated parallel port. Changing the IOPM, allows the process free access to the I/O port range of the parallel port hardware. It also supports additional parallel ports added using expansion cards.
|
|||||||||||||||||||||||
The Details | The
API calls are provided in a Win32 DLL. One call is all that is required to use the direct
I/O functionality. The Win32 application is linked with the supplied import library and
the kernel driver is demand loaded as necessary. No tampering with the registry or
rebooting is needed. The API calls are documented here: Include the header file for definitions and function prototypes. #include "ParllIo.h" The GetParallelPortCount API returns the number of parallel ports present in the PC. INT WINAPI GetParallelPortCount(VOID) Return value:
The GetParallelPortInfo API returns information about the a particular indicated parallel port, such as the physical I/O port address and number of I/O port addresses spanned by the hardware device. BOOL WINAPI GetParallelPortInfo( Arguments:
Return value:
typedef struct { Arguments:
Return value:
The ReleaseParallelPort API frees the parallel port for use by another process. Direct I/O should not be performed after this function is called. If this function is not called, the application will own the parallel port until the application exits or is terminated. BOOL WINAPI ReleaseParallelPort( Arguments:
Return value:
For Visual Basic users six functions are provided for input and
output as follows: INT WINAPI OutWord( INT WINAPI OutDWord( INT WINAPI InByte( INT WINAPI InWord( INT WINAPI InDWord( |
|||||||||||||||||||||||
I/O Timing | I/O instructions executing in user mode
(ring 3) will take longer than executing in kernel mode (ring 0). It is however, dependant
upon the processor, but the number of clocks taken is generally two to three times that of
comparable real-mode (i.e. MS-DOS) execution.
|
|||||||||||||||||||||||
Installation | The Direct I/O Access developer package
consists of a header file ParllIo.h containing definitions and function prototypes, a Microsoft Visual C++ 5.0
compatible import library ParllIo.lib to be linked with the application and some example test programs. Both C and
Visual Basic examples are supplied. The Direct I/O Access runtime package consists of two files, a kernel mode driver ParllIo.sys and a dynamic link library, ParllIo.dll. These files should be distributed with the application. The driver may either be loaded on-demand or may be loaded when the system boots. If the driver is loaded on-demand, the user running the application must have NT administrator rights. If it is envisiged that the user running the program will not have NT administrator rights, the driver can be installed to load at boot. NT administrator rights are still needed during setup, but once completed the driver can be used by non administrative users. A setup program is provided to create the necessary registry entries to load the driver at boot. It can be run in quiet mode so that it can be called from the application setup program or in interactive mode. If the driver will be loaded on-demand, the application setup program can copy the files into the application directory. Running the command setup /h show the setup program options. To perform a quiet mode installation from another setup program, run the following command setup c:\winnt /q.This will copy ParllIo.sys to the system32\drivers directory and ParllIo.dll to the system32 directory and make the necessary registry entries to load the driver on boot. Alternatively, use the setup program in interactive mode as shown below.
|
|||||||||||||||||||||||
Windows 95/98 Support | Under Microsoft Windows 95/98
direct port I/O is allowed to certain I/O address ranges. The parallel ports are one such
range. When running under Win 95/98, the library ParllIo.dll skips the calls to the kernel driver allowing the same code base and file
set to be shipped for both Windows NT and Windows 95/98. Note: Release of a Win 95/98 driver allowing coordinated access to parallel ports may be released if there is sufficient demand.
|
|||||||||||||||||||||||
License Agreements | Click
here to read the development license agreement. Click here to read the run-time license agreement. |