Guardian Programmer's Guide

Table Of Contents
Communicating With Printers
Guardian Programmer’s Guide 421922-014
11 - 4
A Printer Program Outline
A Printer Program Outline
The general approach to directly accessing a line printer from an application program
is:
1. Open the printer by calling the FILE_OPEN_ procedure. Use the printer file name
to identify the printer to the FILE_OPEN_ procedure. To prevent your printed
messages being mixed with messages printed by other processes, you should
open the printer for exclusive access.
2. For a matrix line printer, position the paper to the top of the form by using the
CONTROL procedure. Operation 1 allows you to adjust the paper position.
3. Call the WRITE[X] procedure to print each line of text.
4. When you have finished using a matrix line printer, call the CONTROL procedure
to position the paper again to the top of the form. Then call the FILE_CLOSE_
procedure to terminate your access to the printer.
The code fragments shown below illustrate this technique:
LITERAL MAXLEN = 256;
.
.
STRING .PRINTER^NAME[0:MAXLEN - 1] := "$LP1";!printer
! name is $LP1
INT PRINTER^NUM; !printer file number
STRING .SBUFFER[0:132]; !print buffer
STRING .S^PTR;
LITERAL EXCLUSIVE = ZSYS^VAL^OPENEXCL^EXCLUSIVE;
LITERAL POSITION = 1;
LITERAL TOP^OF^FORM = 0;
.
.
!Open the printer for exclusive access:
LENGTH := 4;
ERROR := FILE_OPEN_(PRINTER^NAME:LENGTH,
PRINTER^NUM,
EXCLUSIVE);
IF ERROR <> 0 THEN ...
!Move to the top of the form:
CALL CONTROL(PRINTER^NUM,
POSITION,
TOP^OF^FORM);
IF <> THEN ...
.
.
!Send text to printer:
SBUFFER ':=' "Print just one line on the printer" -> @S^PTR;
CALL WRITEX(SBUFFER,
PRINTER^NUM,
@S^PTR '-' @SBUFFER);
IF <> THEN ...