Contents

3.8 VIRTUAL_PRINTER package

If you have ever tried to use TEXT_IO to send data to a printer, you know you have to know the name of the printer to open it. If you are using DOS on a PC, there is a good chance the printer will be connected to LPT1, but it doesn't have to be. On VMS the printer could be on just about any port, so you can't assume TXA7: will always be the printer port. (In most cases it won't.)

3.8.1 What's Its Name?

What are you going to do if you want to write a program that sends data to a printer? You could ask the user the name of the printer every time. That's a bad idea because it is a nuisance to the user, and the user might not even know the name of the printer port. You could code the printer port name right into your application program, but that can cause maintenance and portability problems. Suppose the central computing facility reconfigures the system, and moves the printer to another port. You would have to search through all your application programs to find every place you have named the printer port. You would have to do the same thing if you wanted to use your programs on another computer.

My solution is to write a package called VIRTUAL_PRINTER (Listing 54) which has the name of the printer hidden in the body. If you ever need to change the name of the printer port, you just have to change the name in the VIRTUAL_PRINTER body, recompile it, and relink any application programs that use it. You don't need to recompile the affected application programs because they depend on the VIRTUAL_PRINTER specification, and you've only had to change the body. All you have to do is relink them. (An Ada programming environment ought to be able to give you a list of all units that depend on the VIRTUAL_PRINTER package specification, so you will know which programs to relink.)

3.8.2 Printer Quirks

The VIRTUAL_PRINTER body is also a good place to take care of printer quirks. Many years ago I ran across a printer that used an escape sequence instead of the normal ASCII form feed character to advance to the top of a page. There may not be any of those printers around any more, but if there are, you can put some code in the VIRTUAL_PRINTER body that substitutes the appropriate escape sequence whenever it receives a form feed.

The first printer I attached to my IBM PC AT clone was my old reliable Microline 83 printer, which had served my CP/M system for five years. It was configured for 1200 baud serial operation, and I put it on the COM2 port. Modern printers buffer several thousand characters, but in 1982 serial printers only buffered a line or two. At the end of each line the Microline 83 used an RS-232C control signal to tell the computer not to send any more data because it was busy printing the data in the buffer. My new computer expects the printer to use CONTROL_Q and CONTROL_S to tell it when to start and stop sending data, and must not bother to check the RS-232C control lines. Consequently, the first character of a line would sometimes be sent while the printer was still printing, and wouldn't get into the print buffer.

This is not a new problem. The original teletypewriter terminals took a long time for the print cylinder to return to the first column. They used a 20 milliamp current loop, and didn't have any extra control lines in those days. Since they didn't have any way of telling when the print cylinder was ready to print again, they routinely sent a few null characters after every carriage return. Nulls aren't printed, so it doesn't matter if they get lost or not. (Now you know why electronic bulletin boards sometimes ask you if you require any nulls.) Figure 33 shows that I solved my problem in exactly the same way.

When I bought my Epson LQ-850, I put it on the parallel port LPT1. All I had to do to was make the changes shown in Listing 55, and all my old programs would send data to by new printer.

You will almost certainly have to write your own VIRTUAL_PRINTER body, but it shouldn't be too difficult. All you have to do is know the logical name of the printer.


Contents | Next ...