Control the printer from within a Modula-2 program
On many an occasion you need to know if the printer is available from within your programs. DOS and the BIOS
supply functions for this, so that looks more professional than 'asking the user to check if the small green
LED is on'. Most users will start asking what a LED is.
This small library can be useful to give your programs that little bit of >>--Zing--> because your program can just TELL the user to put the printer on-line, or whatever. It also offers easy possibilities for paper ejecting and setting typeface functions.
I cut out both GPL notices. because they take up too much space and bandwidth. You should know by now that all my published sources are published as GNU GPL material.
DEFINITION MODULE for printer control library
DEFINITION MODULE Printer; (* GNU GPL removed, see text. *) TYPE PrinterStatus = (Ready, Offline); LogicState = (On, Off); PrnCommand = (Reset, Eject, Portrait, LandScape); PROCEDURE CheckPrinter () : PrinterStatus; (* This procedure tests if the printer is on-line or off-line. It reports "Ready" if ready to accept data, or "Offline" when the machine is offline for any reason. *) PROCEDURE Bold (state : LogicState); (* Set the current typeface to BOLD or back to normal *) PROCEDURE Italics (state : LogicState); (* Make characters appear slanted or upright *) PROCEDURE FontSize (size : CARDINAL) (* Set the characterheight in mm. *) PROCEDURE MakePrinter (command : PrnCommand); (* Issue various commands to the printer: FormFeed, Reset, Portrait, Landscape. *) END Printer.
IMPLEMENTATION MODULE for printer control library
IMPLEMENTATION MODULE Printer; (* GNU GPL removed, see text. *) IMPORT ASCII; FROM InOut IMPORT Write, WriteCard, WriteString; FROM SYSTEM IMPORT ASSEMBLER; PROCEDURE CheckPrinter () : PrinterStatus; (* Use INT 17H to get printerstatus *) VAR Status : CARDINAL; BEGIN ASM MOV AH, 1 MOV DX, 0 INT 17H MOV AL, AH MOV AH, 0 MOV [Status], AX END; IF Status = 90H THEN RETURN Ready ELSE RETURN Offline END END CheckPrinter; PROCEDURE Bold (state : LogicState); BEGIN Write (ASCII.ESC); IF state = On THEN WriteString ('(s4B') ELSIF state = Off THEN WriteString ('(s0B') END END Bold; PROCEDURE Italics (state : LogicState); BEGIN Write (ASCII.ESC); IF state = On THEN WriteString ('(s1S') ELSIF state = Off THEN WriteString ('(s0S') END END Italics; PROCEDURE FontSize (size : CARDINAL); BEGIN Write (ASCII.ESC); Write ('('); Write ('s'); size := size * 4; WriteCard (size, 1); Write ('V') END FontSize; PROCEDURE MakePrinter (command : PrnCommand); BEGIN IF command = Reset THEN Write (ASCII.ESC); Write ('E') ELSIF command = Eject THEN Write (ASCII.FF) ELSIF command = Portrait THEN Write (ASCII.ESC); WriteString ('l0O') ELSIF command = LandScape THEN Write (ASCII.ESC); WriteString ('l1O') END END MakePrinter; END Printer.
Some comments on the printer control library
Short, isn't it? If you have questions, just send a note to me by E-mail, using the link in the navigator frame on the right.
Of course this library has been written with my Laserjet IIIP as a target. If you have another printer, you must change the printer command codes.
Source created 1994 and