Printer Ready -- Test

 BBS: Inland Empire Archive
Date: 09-21-93 (17:47)             Number: 18
From: ROB SMETANA                  Refer#: NONE
  To: ALL                           Recvd: NO  
Subj: Printer Ready -- Test          Conf: (2) Quik_Bas
'================  CheckPRN.Bas (Printer Ready)  ==================
'
'   Please run this and report results.  Thanks!
'
'   1st cut:  Ron Sharrad
'
'   2nd cut:  Rob Smetana  (multiple ports, trap more errors, etc.)
'             Use as you see fit.
'==================================================================
DEFINT A-Z
DECLARE FUNCTION CheckPRN (PortNum) '...PortNum must be 1, 2 or 3!
CLS

'...Printer error codes we've seen so far
   OffLine1 = 87                '...87 Epson   71 HP LaserJet
   OffLine2 = 71
  PaperOut1 = 119               '...we also got 119 w/ the cable off!
  PaperOut2 = 103               '...119 Epson  103 HP LaserJet
     NotOn1 = 127               '...127 another author suggested this
     NotOn2 = 135               '...135 Epson  135 HP LaserJet
  PrnReady1 = 223               '...223 Epson  223 HP LaserJet
  PrnReady2 = 222               '...222 another author suggested this
PortNotFound = 0                '...no LPT port found


FOR PortNum = 1 TO 5            '...Try 1-5 to ensure we can
                                '   trap "invalid port" errors
    PRINT : PRINT

    ErrCode = CheckPRN(PortNum)

    PRINT USING "Code: (####).  LPT# is "; ErrCode; PortNum;

    SELECT CASE ErrCode
        CASE PortNotFound
            PRINT "nowhere to be found!";

        CASE OffLine1, OffLine2
            PRINT "off line!";

        CASE PaperOut1, PaperOut2
            PRINT "out of paper (or cable's not connected)!";

        CASE NotOn1, NotOn2
            PRINT "turned off! ";

        CASE PrnReady1, PrnReady2
            PRINT "ready!";

        CASE IS > 250
            PRINT "NOT a valid port number.  Set PortNum to 1 - 4!";

        CASE ELSE
            PRINT "(who knows).  Unknown error code.  Report this.";
    END SELECT
NEXT
'
FUNCTION CheckPRN (PortNum)     '...Printer ready function
'
    '...<rws> check any port (not just #1)
    '...PEEK into the BIOS data segment.  Addresses of LPT ports
    '   (words/integers) are at offset 8, 10, 12, etc.  Since LPT
    '   ports are actually numbered 0, 1, etc., use "(PortNum - 1)"
    '   below.

    OffSet = 8 + ((PortNum - 1) * 2)    '...yields 8, 10, 12, etc.

    DEF SEG = &H40

    'Sharrad's original (LPT1): PrnPrt& = PEEK(9) * &H100 + PEEK(8)+1

    PrnPort& = PEEK(OffSet + 1&) * 256& + PEEK(OffSet)

    '... if PrnPrt& = 0, that printer port does NOT exist
    IF PrnPort& = 0 THEN
       CheckPRN = PrnPort&
    ELSE
       CheckPRN = INP(PrnPort& + 1&)
    END IF

    DEF SEG
END FUNCTION
$$
--- RBBSMail 17.3A
 * Origin: PCUG BBS - San Francisco HST/V.32 415-621-2609 (RBBS 1:125/41.0)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET