Sending Control Codes to ImageWriter I, II, LQ from QuickBASIC (46815)



The information in this article applies to:

  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0

This article was previously published under Q46815

SUMMARY

This article discusses how to control printing to an Apple ImageWriter I, II, or LQ from Microsoft QuickBASIC Version 1.00 for the Apple Macintosh.

A QuickBASIC program can either open a printer device name or the communications ("COM1:") port for output. These methods have the advantages and disadvantages described below.

MORE INFORMATION

The following features allow a QuickBASIC program to print to the Apple ImageWriter I, II, and LQ printers:

  1. The Print item in the File menu (to print a source listing)
  2. OPEN "LPT1:" FOR OUTPUT AS #n
  3. OPEN "LPT1:PROMPT" FOR OUTPUT AS #n
  4. OPEN "COM1:baud,parity,data,stop" FOR OUTPUT AS #n
The first three features above (Print from the File menu, "LPT1:", and "LPT1:PROMPT") work with either a direct connection or a connection through the AppleTalk Network. However, output to "COM1:" requires a direct connection and does not work over an AppleTalk Network.

Note that the LPRINT statement, "LPT1:DIRECT" device name, and "LPT1:BIN" (which all support sending control characters byte by byte) work only on a directly connected ImageWriter I or II and do not print to an ImageWriter LQ or to the AppleTalk Network.

There are two alternatives to change the print style or invoke special printing modes for the ImageWriter I, II, and LQ:

  1. Use the OPEN statement to open "LPT1:" or "LPT1:PROMPT" as #n. At this point, a PRINT#n or WRITE#n statement uses the default application text font and size.

    If you now invoke the WINDOW OUTPUT #n statement, you can redirect the window output of most ROM routines to the printer. This is one of the most useful features in QuickBASIC. Subsequent ROM routines (such as TEXTFONT, TEXTSIZE, TEXTMODE, TEXTFACE, and TEXTMODE) can change the text appearance printed by subsequent PRINT statements. (Be sure to use PRINT, not PRINT#n, when WINDOW OUTPUT #n is in effect.) The CLOSE#n statement, or filling up a full page, sends the bitmapped output to the printer.

    A disadvantage of the "LPT1:" and "LPT1:PROMPT" device names is that they don't support ImageWriter-specific control characters. Apple's ImageWriter printer driver converts the output to a bitmap. This process is incompatible with byte-by-byte printer control codes or "escape" sequences.
  2. Use the OPEN statement to open "COM1:" as #n. At this point, a PRINT#n statement can optionally send byte-by-byte printer control codes (or "escape" sequences), which are listed in the back cover of Apple's user's guide for the ImageWriter I, II, or LQ.

    When opening the COM1: port for printing to the ImageWriter LQ, you must use a baud rate of 19,200, no parity, 8 data bits, and 1 stop bit.

    When opening the COM1: port for printing to the ImageWriter I or II, you must use a baud rate of 9600, no parity, 8 data bits, and 1 stop bit.

    When printing to COM1:, you must also send carriage return and linefeed characters at the end of each line, i.e., CHR$(13)+CHR$(10).

    A disadvantage of COM1: output is that it does not support the WINDOW OUTPUT #n statement.

Code Example 1

This code example demonstrates how to print to an ImageWriter I, II, or LQ through the LPT1: port.
OPEN "LPT1:PROMPT" FOR OUTPUT AS #1
' WINDOW OUTPUT #n allows TEXTFONT, TEXTSIZE, LINE, CIRCLE,
' and other ROM graphics:
WINDOW OUTPUT #1   ' IMPORTANT: the # character is required here.
TEXTFONT 4
TEXTSIZE 9
FOR i = 1 TO 10
   PRINT "This is number ", i
NEXT i
CLOSE #1
END
				

Code Example 2

This code example demonstrates how to print to a directly connected ImageWriter LQ through the COM1: port. This program requires a directly connected printer and will not work over the AppleTalk Network.

To print to a directly connected ImageWriter I or II, you must change the baud rate from 19,200 to 9600 in the program below. Better yet, don't use this program for a directly connected ImageWriter I or II. Instead, use the LPRINT statement, or WRITE# or PRINT# to the "LPT1:DIRECT" or "LPT1:BIN" device name (which are not supported to the LQ).
OPEN "COM1:19200,n,8,1" FOR OUTPUT AS #1
' Send ImageWriter escape sequences for bold-faced, ultracondensed:
GOSUB HANDSHAKE  ' Turn on hardware handshaking to prevent overflow
PRINT #1, CHR$(27)+CHR$(33)
PRINT #1, CHR$(27)+CHR$(81)
' Send some characters:
FOR i = 1 TO 10
   PRINT #1, "This is number ", i
   ' Send a carriage return and line feed sequence
   PRINT #1, CHR$(10)+CHR$(13)
NEXT i
CLOSE #1
END
' To avoid possible COM1: buffer overflow, you must turn on
' hardware handshaking as follows:
HANDSHAKE:
   DIM Code%(100)  ' Array size must be at least 100.
   n=0 : hdhs=0
   FOR j=0 TO 15
     READ n  ' This loop READs machine language code into an array.
     Code%(j)=n
   NEXT
   hdhs=VARPTR(Code%(0))    ' Get address of array.
   CALL hdhs  ' Call machine language instructions (stored in array).
   RETURN
' Below are machine language instructions (represented as
' hexadecimal constants) that invoke the _CONTROL ROM routine.
DATA &H41FA,&H001E
DATA &H317C,&HFFF9,&H18
DATA &H317C,&H000A,&H001A
DATA &H217C,&H001,&H1113,&H1C
DATA &H42A8,&H0020
DATA &HA004
DATA &H4E75
				

Modification Type:MinorLast Reviewed:1/9/2003
Keywords:KB46815