Microsoft KB Archive/46815

= Sending Control Codes to ImageWriter I, II, LQ from QuickBASIC =

Article ID: 46815

Article Last Modified on 1/9/2003

-

APPLIES TO


 * Microsoft QuickBasic Compiler for 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 (&quot;COM1:&quot;) 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 &quot;LPT1:&quot; FOR OUTPUT AS #n
 * 3) OPEN &quot;LPT1:PROMPT&quot; FOR OUTPUT AS #n
 * 4) OPEN &quot;COM1:baud,parity,data,stop&quot; FOR OUTPUT AS #n

The first three features above (Print from the File menu, &quot;LPT1:&quot;, and &quot;LPT1:PROMPT&quot;) work with either a direct connection or a connection through the AppleTalk Network. However, output to &quot;COM1:&quot; requires a direct connection and does not work over an AppleTalk Network.

Note that the LPRINT statement, &quot;LPT1:DIRECT&quot; device name, and &quot;LPT1:BIN&quot; (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 &quot;LPT1:&quot; or &quot;LPT1:PROMPT&quot; 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 &quot;LPT1:&quot; and &quot;LPT1:PROMPT&quot; 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 &quot;escape&quot; sequences.
 * 1) Use the OPEN statement to open &quot;COM1:&quot; as #n. At this point, a PRINT#n statement can optionally send byte-by-byte printer control codes (or &quot;escape&quot; 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 &quot;LPT1:PROMPT&quot; 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 &quot;This is number &quot;, 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 &quot;LPT1:DIRECT&quot; or &quot;LPT1:BIN&quot; device name (which are not supported to the LQ). OPEN &quot;COM1:19200,n,8,1&quot; 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, &quot;This is number &quot;, 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

Additional query words: MQuickB

Keywords: KB46815

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.