INF: Verifying the Printer Connection

ID Number: Q77467

3.00

WINDOWS

Summary:

The PC ROM BIOS printer services function Get Printer Status (INT 17H

Function 2H) can be used to determine if a printer is connected to a

specific port. To save time and potential data loss, an application

can use INT 17H Function 2H to determine if a printer is present

before entering the application's printing code. This article contains

code to make this determination.

More Information:

The following code defines a function IsPrinter():

/***************************************************************

* *

* Name: IsPrinter - tests if printer is connected *

* *

* Parameters: AX = 02h *

* DX = printer number (LPT1 = 0) *

* *

* Return AH = status bits *

* 01h time out *

* 02h unused *

* 04h unused *

* 08h I/O error *

* 10h printer selected *

* 20h out of paper *

* 40h printer acknowledgment *

* 80h printer not busy *

* *

* Function returns 1 if printer connected *

* returns 0 otherwise *

* *

***************************************************************/

int IsPrinter(void)

{

unsigned char iRetVal = 0;

_asm

{

mov ah, 02h

mov dx, 0 /* 0 is number for LPT1: */

int 17h

mov iRetVal, ah

}

if (iRetVal == 0x90)

return (1);

else

return (0);

}

For more information, please refer to "The MS-DOS Encyclopedia"

(Microsoft Press). Pages 163 and 164 contain an example of interrupt

driven communication with the printer. Appendix O details the ROM BIOS

functions and their parameters.