[Access to Wang masthead]

Spellbound

Mastering printer control codes - first of a two-part series

From "VS Workshop",  Access to Wang, April 1990
  [ Prior Article ]     [ Return to the Catalog of articles ]     [ Next Article ]  

Like a growing number of VS users, I use a PC as my VS workstation; like many, I have an attached PC printer. The printer allows me convenient access to information and some capabilities not normally available, such as printing a screen dump of a Word Processing screen. File transfer software allows me to send print files from the VS to my PC printer, and I take full advantage of this capability for short listings and other needs.

The trouble is, I'm never sure about the character size and print quality settings on the printer. The matrix printer I use allows only pitch control from the main panel, and visitors to my office will often find me hunched over the printer setting the character size for a VS print file I'm about to transfer. This is not a good position to assume when you're trying to impress people.

Our organization also sends reports of various widths to field users. I became concerned about the possibility of one of these users attempting to print a wide-format report with narrow paper in the printer without first setting to condensed mode. This seems a minor problem, but I have ruined an expensive print head myself through the same mistake.

We also use a variety of non-Wang printers on the VS. Some of these printers are connected through normal coaxial cables (the 928 link); others are attached to the Multi-Line Telecommunications IO Controller (MLTC IOC) and communicate by imitating a 2110 terminal. In all cases, these industry-standard printers have far more printing capabilities than humble VS DP print files can directly control.

Or can they? After some experimentation, I have found that printer control characters imbedded into VS print files can control printers attached through all of these means. If you have similar needs, read on.

Print file structures

VS data processing print files consist of two Printer Control Characters (PCCs) followed by the text to be printed. The PCCs control line feeds, form feeds, and a few printer features, such as expanded print. The text area is variable in length and compressed, resulting in a very compact file. As a compressed, consecutive file, VS print files cannot be modified through normal means; they can, however, but read by a program and written into a new file.

Typical values for the first PCC byte include '80 (advance page), '00 (print line after advancing lines) and '40 (print line before advancing lines); less common is '20 (print line with expanded characters). Other PCC combinations exist, but may be related to specific printers or applications; see the Principles of Operation manual for further details. Two interesting notes: first, the use of '00 in both PCC bytes has a "null" effect (no effect to the printer); second, any text from the third byte on is sent directly to the printer.

Terminal emulation software and other VS-to-PC file transfers must convert VS print files to PC format. PC print files are far more varied in structure, but there are several assumptions that can be made. Most use the hex character '0C to perform a page feed, and most separate the line feed and carriage return functions so that lines may be printed twice - as with underlines and emphasized print mode. Like VS print files, there is no standard means of controlling character size or quality, form line spacing, or other qualities; instead, each printer manufacturer has devised their own set of control characters. Thus, you must know the control requirements of the printer that will receive the file before you can assume control of the printer's features.

All of the file transfer software I have tested converts the PCC bytes to standard PC printer control codes, but passes the text area verbatim. This means that printer control information can be disguised as text within a print file and passed directly to the printer.

Understanding escape codes

Printer control characters are known as escape codes because they often use the escape character (hex '1B) to separate control information from the text to be printed. The types of control include:

Almost all modern printers come with manuals that explain how printer features can be accessed. Typically, there are BASIC programming examples shown - though few of us work routinely with BASIC and the examples are of little help. If you're like most people, you probably glanced at the manual and threw it on the bookshelf. Pull it down now; we'll need it.

While every manufacturer has their own ideas about printer control, there are several printer types that others imitate. The most prevalent in the current PC world are the Epson LQ series, the IBM ProPrinter, and the Hewlett-Packard LaserJet. Other printer manufacturers - Brother, Panasonic, Okidata, etc. - set up their printers to look like one or more of these three. If your printer gives you a choice, check now to see which emulation is active.

Suppose you wished to set up the printer for 17 pitch draft mode to print those 132-column reports. The related escape codes required for the three printers are shown in Figure 1, below.

Example: creating a printer control file

With an understanding of the structure and capabilities of escape codes, let's build a VS print file that controls a remote printer. Our file will set the 17-pitch compressed mode using the Epson LQ escape codes. The CREATE utility is a convenient tool for this purpose, although any programming language would allow greater flexibility and control.

Figure 2 shows a short procedure to make this file. It uses the &BYTE function of Procedure language to load the escape codes into a string, then moves that string into the LITERAL screen of CREATE, finally displaying the file. Note that the &BYTE function uses the decimal value rather than the hex values shown in Figure 1, so you may have to make this conversion. (Most printer manuals present escape codes in both bases.)

When the HEX Mode option of DISPLAY is used, the completed file looks like this:


Position:  00 . . . 04 . . . 08 . . . 0C . . . 10
Value:     00001B50 1B78011B 321B4342

Notice that the text area (beginning at byte 3) has been reduced to its non-blank length - even though the record area maximum is 134 characters.

The completed file should be sent to any printer you wish to control. The pitch and print quality of the printer will be affected - provided the correct escape characters have been sent. Similar files can be set up for other common printer parameters.

While potentially useful, the results of this experiment are a far cry from a complete solution to the issues of printer control. Next month I'll continue the discussion with an example of a more refined print file control system.


Figure 1: Printer escape codes - 17 pitch draft

Printer TypeHex CharactersResult
Epson LQ series'1B0F
+ '1B7800
(compressed pitch)
(draft mode)
IBM Proprinter X24'1B4910(draft, compressed)
HP LaserJet'1B287331362E3648
+ '1B28733054
(compressed pitch)
(draft mode)

Figure 2: Procedure TESTCHAR


PROCEDURE TESTCHAR - makes print control character files

DECLARE &CHAR     STRING (128)
ASSIGN  &CHAR
  =  &BYTE(000) !! &BYTE(000)                [ null PCC     ]
  !! &BYTE(027) !! &BYTE(015)                [ 17 pitch     ]
  !! &BYTE(027) !! &BYTE(120) !! &BYTE(000)  [ draft qual.  ]

RUN CREATE IN @SYSTEM@
O1:  DISPLAY OUTPUT   TYPE     = P,
				  RECSIZE  = 134,
				  RECORDS  = 1
	ENTER   INPUT    02
	ENTER   PAD      POSITION = 1,
				  LENGTH   = (O1.RECSIZE)
	ENTER   INPUT    01
	ENTER   LITERAL  STRING   = &CHAR,
				  POSITION = 1
	ENTER   INPUT    16
	ENTER   COUNT    RECORDS  = 1
	ENTER   INPUT    16
	ENTER   EOJ      14
	ENTER   EOJ      16

RETURN

  [ Prior Article ]     [ Return to the Catalog of articles ]     [ Next Article ]  


Copyright © 1990 Dennis S. Barnes
Reprints of this article are permitted without notification if the source of the information is clearly identified