Problems Determining If Printer Is Attached

ID Number: Q60212

2.x 3.00 3.10 3.20 3.21 3.22 3.30 3.30a 4.00 4.01

MS-DOS

Question:

Remove any printer cable connected to your computer. Then execute the

following command:

MODE LPT1 132,8

The following message will be displayed indicating that the printer

has been successfully installed:

LPT1: set for 132 Printer lines per inch set

When there is no printer present, shouldn't a more appropriate

message, such as "No printer available," be displayed?

Response:

There is no way to determine if there actually is a printer attached

to the printer port. You can put in code to test for this situation,

but it won't work 100 percent of the time. It will work sometimes,

with some printer/adapter combinations, under some circumstances.

The reason you cannot detect if the printer is attached to a printer

port all the time is because of a hardware problem, not a problem in

MS-DOS. Most IBM (and compatible) printer adapters do not have the

status lines pulled high or low. Thus, when a printer is not hooked

up, the status lines will float. Depending on the card and other

random factors, sometimes the lines will float high, sometimes low. If

the lines float to the right state, the status will be OK even though

there is no printer connected. This is true even on the newest IBM

ATs. The status lines on Centronix adapters used by IBM are not

pulled, the lines float, and thus take random values.

There is a way to tell if there is a printer adapter present, but not

whether it has a printer connected to it. You can even try to send a

character to see if you get an error; this, too, will sometimes appear

to work if the status lines are floating in such a way as to make it

appear that the character was received.