home *** CD-ROM | disk | FTP | other *** search
- #include <Printing.h>
- #include <Resources.h>
- #include <Memory.h>
- #include <Dialogs.h>qq
- #include <OSUtils.h>
- #include <OSEvents.h>
- #include <Fonts.h>
- #include <Menus.h>
- #include <Serial.h>
- #include <stdio.h>
- #include <OSUtils.h>
-
-
- /* Copyright 1992 Apple Computer Developer Technical Support */
- /* 3-9-92 - completed - Brigham Stevens */
-
- /* This sample program demonstrates how to determine:
- 1. If an ImageWriter is connected
- 2. What type of ImageWriter
- 3. Which port it is connected to (invalid if AppleTalk IW)
- */
-
- /* these are the wDev IDs for the ImageWriter and IW LQ printers */
- /* see the Q & A Stack for a discussion of the wDev field. */
- #define IMAGE_WRITER_WDEVID 1
- #define IMAGE_WRITER_LQ_WDEVID 5
-
-
- /*
- This is returned from the IsImageWriter function to
- indicate which kind of ImageWriter is returned.
- a result of zero, or NotImageWriter means that the
- printer is - not an ImageWriter.
-
- */
- typedef enum {
- NotImageWriter,
- SerialImageWriter,
- AppleTalkImageWriter,
- SerialImageWriterLQ,
- AppleTalkImageWriterLQ
- } ImWrtKindFlag;
-
-
- ImWrtKindFlag IsImageWriter()
- /*
- This function determines if we are talking to an ImageWriter and
- then if so, what kind. This function is reliant upon the signature
- resource being 'IWRX' for an AppleTalk ImageWriter, or 'IWRT' for a
- serial connected ImageWriter,
- or respectivly 'BWRT', or 'BWRX' for an LQ ImageWriter
- */
- {
- THPrint tpr;
- short prtNum;
- short result = NotImageWriter;
-
- tpr = (THPrint)NewHandle(sizeof(TPrint));
- if(!tpr) {
- result = MemError();
- goto bail;
- }
-
- PrOpen(); /* open the print driver */
- if(result = PrError()) goto bail;
-
- PrintDefault(tpr); /* init the print record */
- if(result = PrError()) goto bail;
-
- /* get the printer ID number from the high byte */
- /* of the wDev field. This is a quasi-unique */
- /* number for each printer type. See the Q & A Stack */
- /* for more information on the wDev field, and the */
- /* problems with relying on it. For the purposed of checking */
- /* for a color ribbon, you should be ok. You may have to */
- /* revise this technique at some point, when the new print architecture */
- /* is available. */
- prtNum = (**tpr).prStl.wDev >> 8;
-
- if ( prtNum == IMAGE_WRITER_WDEVID ) {
- /* we are talking to an ImageWriter, now see
- if it is serial or appleTalk. */
- if(Count1Resources('IWRT') > 0)
- result = SerialImageWriter;
- else if(Count1Resources('IWRX') > 0)
- result = AppleTalkImageWriter;
- else /* This must be a printer acting like an ImageWriter */
- result = NotImageWriter;
- }
- else if ( prtNum == IMAGE_WRITER_LQ_WDEVID ) {
- if(Count1Resources('BWRT') > 0)
- result = SerialImageWriterLQ;
- else if(Count1Resources('BWRX') > 0)
- result = AppleTalkImageWriterLQ;
- else /* This must be a printer acting like an ImageWriterLQ */
- result = NotImageWriter;
- }
- bail:
- if(tpr)
- DisposHandle((Handle)tpr); /* get rid of our print handle */
- PrClose(); /* close the print driver */
- return result;
- }
-
- SPortSel GetPrinterConnection()
- /*
- This function returns sPortA or sPortB, whichever
- the printer is connected to, as determined from
- parameter RAM. Note: the result is only valid in
- the case where you have a printer that is connected
- directly to the Macintosh.
- */
- {
- SysPPtr pRAMptr; /* See IM-II pg. 370 */
-
- pRAMptr = GetSysPPtr(); /* See IM-II pg. 381 */
-
- /* bit zero indicates which port */
- /* bit zero = 0 = printer port */
- /* bit zero = 1 = modem port */
- if(pRAMptr->kbdPrint & 0x0001)
- return sPortA; /* Modem Port */
- else
- return sPortB; /* Printer Port */
- }
-
- main ()
- {
-
- ImWrtKindFlag iw;
- SPortSel whichPort;
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- InitCursor();
- TEInit();
- FlushEvents(everyEvent, 0);
- InitDialogs(nil);
-
- printf("\n");
- switch(iw = IsImageWriter()) {
- case NotImageWriter:
- printf("\nWe are NOT connected to an ImageWriter.");
- break;
- case SerialImageWriter:
- printf("\nWe are connected to a Serial ImageWriter.");
- break;
- case AppleTalkImageWriter:
- printf("\nWe are connected to an AppleTalk ImageWriter.");
- break;
- case SerialImageWriterLQ:
- printf("\nWe are connected to a Serial ImageWriterLQ.");
- break;
- case AppleTalkImageWriterLQ:
- printf("\nWe are connected to a AppleTalk ImageWriterLQ.");
- break;
- default:
- printf("\nIsImageWriter error code: %i",iw);
- }
- whichPort = GetPrinterConnection();
- if(whichPort == sPortA)
- printf("\nThe printer is connected to the modem port.");
- else if(whichPort == sPortB)
- printf("\nThe printer is connected to the printer port.");
- else
- printf("\nThe printer is connected to an unknown port.");
- printf("\n");
- }