home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / parallel / parallel3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-03  |  3.8 KB  |  98 lines

  1. /*  parallel.c - Simple, abortable example of parallel.device usage
  2.  *
  3.  * Copyright (c) 1990 Commodore-Amiga, Inc.
  4.  *
  5.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  6.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  7.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  8.  * information on the correct usage of the techniques and operating system
  9.  * functions presented in this example.  The source and executable code of
  10.  * this example may only be distributed in free electronic form, via bulletin
  11.  * board or as part of a fully non-commercial and freely redistributable
  12.  * diskette.  Both the source and executable code (including comments) must
  13.  * be included, without modification, in any copy.  This example may not be
  14.  * published in printed form or distributed with any commercial product.
  15.  * However, the programming techniques and support routines set forth in
  16.  * this example may be used in the development of original executable
  17.  * software products for Commodore Amiga computers.
  18.  * All other rights reserved.
  19.  * This example is provided "as-is" and is subject to change; no warranties
  20.  * are made.  All use is at your own risk.  No liability or responsibility
  21.  * is assumed.
  22.  *
  23.  *  Compile with Lattice 5.04: LC -Lt -catsfq
  24.  */
  25. #include <exec/types.h>
  26. #include <devices/parallel.h>
  27. #include <libraries/dos.h>
  28. #ifdef LATTICE
  29. #include <proto/exec.h>
  30. #include <stdio.h>
  31. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL-C handling */
  32. void main(void);
  33. #endif
  34.  
  35. #define DEVICE_NAME "parallel.device"
  36. #define UNIT_NUMBER 0
  37.  
  38. void main()
  39. {
  40. struct MsgPort  *ParallelMP;          /* Define storage for one pointer */
  41. struct IOExtPar *ParallelIO;         /* Define storage for one pointer */
  42. ULONG            WaitMask;          /* Collect all signals here       */
  43. ULONG            Temp;             /* Hey, we all need pockets :-)   */
  44.  
  45. if( ParallelMP=CreatePort(0,0) )
  46.     {
  47.     if( ParallelIO=(struct IOExtPar *)
  48.         CreateExtIO(ParallelMP,sizeof(struct IOExtPar)) )
  49.         {
  50.         ParallelIO->io_ParFlags=0;    /* Example of setting flags */
  51.  
  52.         if ( OpenDevice(DEVICE_NAME,UNIT_NUMBER,ParallelIO,0) )
  53.             printf("Parallel.device did not open\n");
  54.         else
  55.             {
  56.             /* Precalculate a wait mask for the CTRL-C, CTRL-F and message
  57.              * port signals.  When one or more signals are received,
  58.              * Wait() will return.  Press CTRL-C to exit the example.
  59.              * Press CTRL-F to wake up the example without doing anything.
  60.              * NOTE: A signal may show up without an associated message!
  61.              */
  62.             WaitMask = SIGBREAKF_CTRL_C|
  63.                        SIGBREAKF_CTRL_F|
  64.                        1L << ParallelMP->mp_SigBit;
  65.  
  66.             ParallelIO->IOPar.io_Command  = CMD_WRITE;
  67.             ParallelIO->IOPar.io_Length   = -1;
  68.             ParallelIO->IOPar.io_Data     = (APTR)"Hey, Jude! \015\012";
  69.             SendIO(ParallelIO);             /* execute write */
  70.  
  71.             printf("Sleeping until CTRL-C, CTRL-F, or write finish\n");
  72.             while(1)
  73.                 {
  74.                 Temp = Wait(WaitMask);
  75.                 printf("Just woke up (YAWN!)\n");
  76.  
  77.                 if( SIGBREAKF_CTRL_C & Temp)
  78.                     break;
  79.  
  80.                 if( CheckIO(ParallelIO) ) /* If request is complete... */
  81.                     {
  82.                     WaitIO(ParallelIO);   /* clean up and remove reply */
  83.                     printf("%ld bytes sent\n",ParallelIO->IOPar.io_Actual);
  84.                     break;
  85.                     }
  86.                 }
  87.  
  88.             AbortIO(ParallelIO);  /* Ask device to abort request, if pending */
  89.             WaitIO(ParallelIO);   /* Wait for abort, then clean up */
  90.  
  91.             CloseDevice(ParallelIO);
  92.             }
  93.         DeleteExtIO(ParallelIO);
  94.         }
  95.     DeletePort(ParallelMP);
  96.     }
  97. }
  98.