Jump to page content

How to check to see that a printer is online

The hard way.

Long before we had bidirectional parallel communication and modern printer drivers, and when we did all of our printing in plain text on 9-pin dot matrix printers, checking to see if a printer was switched on and set as online within your code was not so easy. You had to do something like this code fragment from LSAIT Hangman:

 2430DEFFNck:LOCALa,t,q:a=1
 2440PROCm("Testing for printer..."):OSCLI("FX21,3"):t=ADVAL(-4)
 2450OSCLI("FX3,10"):VDU127,127,127:OSCLI("FX3,0"):q=INKEY25:IFADVAL(-4)<t a=0
 2460IFa=0PROCm("Oops-printer not ready."):t=INKEY(150)
 2470=a

The specifics:

 OSCLI("FX21,3"):t=ADVAL(-4)

Flush the printer output buffer, and read the buffer’s capacity. ADVAL() is designed to read values from the analogue-to-digital converter but with negative arguments will read operating system buffers too.

 OSCLI("FX3,10")

Switch the machine to printer output only. Oddly, the second byte, 10, is silly because OSBYTE 3 only uses three bits (0-2) of its argument; 10 is out of range. However, it is functionally equivalent to correct call of FX3,2. Hey, I didn’t write the original routine.

 VDU127,127,127

Write three backspace characters; these will only be sent to the printer as that is presently the single active output device.

 OSCLI("FX3,0"):q=INKEY25:IFADVAL(-4)<t a=0
Set output back to screen only, pause, and re-read the printer buffer capacity. If the capacity has dropped, at least one of those three backspaces is still sat in the buffer, going nowhere. Were the printer online, it would have silently eaten them and the buffer would have returned to empty, so the determined capacity would not appear to have changed. If the capacity has dropped, the printer ain’t ready.

The original code that I borrowed for this task omitted the pause and I was puzzled to find it to be rather erratic, until I realised that I needed to pause the program to let the OS deal with the request for printed output.

A note on OSCLI

For the curious: yes it does stand for Operating System Command Line Interpreter. A command like FX21,3 of the form FX a[, x[, y]] is a command-line shorthand for an OSBYTE operating system call, where the three parameters a, x and y are passed into the accumulator and X and Y registers on entry. In BBC BASIC (and lots of other BBC software) you can issue any OS command with a *, e.g.

 *FX 3, 10
 *CONFIGURE TUBE
 *HELP BASIC

The * passes everything following the * directly to the OS CLI. A BASIC command OSCLI() exists to invoke OS commands where you want some of the command line to be formed from variables or function output, e.g. OSCLI("FX3, " + outMode%). In the interests of saving space from avoiding unnecessary line numbers, I wanted to cram as much onto each line (without exceeding the screen width) as possible, so I used OSCLI to invoke an OS command execution and then put more code after it on the line. Madness :)