home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 1.2 / amidev_cd_12.iso / reference_library / devices / dev_examples / parallel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-20  |  2.6 KB  |  85 lines

  1. /*
  2.  * Parallel.c
  3.  *
  4.  * Parallel device example
  5.  *
  6.  * Compile with SAS C 5.10: LC -b1 -cfistq -v -y -L
  7.  *
  8.  * Run from CLI only
  9.  */
  10.  
  11. #include <exec/types.h>
  12. #include <exec/io.h>
  13. #include <exec/memory.h>
  14. #include <dos/dos.h>
  15. #include <devices/parallel.h>
  16.  
  17. #include <clib/exec_protos.h>
  18. #include <clib/alib_protos.h>
  19.  
  20. #include <stdio.h>
  21.  
  22. #ifdef LATTICE
  23. int CXBRK(void) { return(0); }     /* Disable Lattice CTRL/C handling */
  24. int chkabort(void) { return(0); }  /* really */
  25. #endif
  26.  
  27. void main(void)
  28. {
  29. struct MsgPort  *ParallelMP;          /* Define storage for one pointer */
  30. struct IOExtPar *ParallelIO;         /* Define storage for one pointer */
  31. ULONG            WaitMask;          /* Collect all signals here       */
  32. ULONG            Temp;             /* Hey, we all need pockets :-)   */
  33.  
  34. if (ParallelMP=CreatePort(0,0) )
  35.     {
  36.     if (ParallelIO=(struct IOExtPar *)
  37.         CreateExtIO(ParallelMP,sizeof(struct IOExtPar)) )
  38.         {
  39.         if (OpenDevice(PARALLELNAME,0L,(struct IORequest *)ParallelIO,0) )
  40.             printf("%s did not open\n",PARALLELNAME);
  41.         else
  42.             {
  43.             /* Precalculate a wait mask for the CTRL-C,CTRL-F and message
  44.              * port signals.  When one or more signals are received, Wait()
  45.              *  will return.  Press CTRL-C to exit the example.  Press
  46.              * CTRL-F to wake up the example without doing anything.
  47.              * NOTE: A signal may show up without an associated message!
  48.              */
  49.             WaitMask = SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_F |
  50.                        1L << ParallelMP->mp_SigBit;
  51.  
  52.             ParallelIO->IOPar.io_Command  = CMD_WRITE;
  53.             ParallelIO->IOPar.io_Length   = -1;
  54.             ParallelIO->IOPar.io_Data     = (APTR)"Hey, Jude!\\r\n";
  55.             SendIO(ParallelIO);             /* execute write */
  56.  
  57.             printf("Sleeping until CTRL-C, CTRL-F, or write finish\n");
  58.             while(1)
  59.                 {
  60.                 Temp = Wait(WaitMask);
  61.                 printf("Just woke up (YAWN!)\n");
  62.  
  63.                 if (SIGBREAKF_CTRL_C & Temp)
  64.                     break;
  65.  
  66.                 if (CheckIO(ParallelIO) ) /* If request is complete... */
  67.                     {
  68.                     WaitIO(ParallelIO);   /* clean up and remove reply */
  69.                     printf("%ld bytes sent\n",ParallelIO->IOPar.io_Actual);
  70.                     break;
  71.                     }
  72.                 }
  73.  
  74.             AbortIO(ParallelIO);/* Ask dev. to abort request if pending */
  75.             WaitIO(ParallelIO); /* Wait for abort, then clean up */
  76.  
  77.             CloseDevice((struct IORequest *)ParallelIO);
  78.             }
  79.         DeleteExtIO(ParallelIO);
  80.         }
  81.     DeletePort(ParallelMP);
  82.     }
  83. }
  84.  
  85.