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

  1. /*
  2.  * Terminate_Parallel.c
  3.  *
  4.  * This is an example of using a termination array for writes from the
  5.  * parallel device. A termination array is set up for the characters Q, E,
  6.  * A and %. The EOFMODE flag is set in io_ParFlags to indicate that we want
  7.  * to use a termination array by sending the PDCMD_SETPARAMS command to the
  8.  * device. Then, a CMD_WRITE command is sent to the device with io_Length
  9.  * set to -1. The write will terminate when one of the four characters in
  10.  * the termination array is sent or when the end of the write buffer has
  11.  * been reached.
  12.  *
  13.  * Compile with SAS C 5.10  lc -b1 -cfistq -v -y -L
  14.  *
  15.  * Run from CLI only
  16.  */
  17.  
  18. #include <exec/types.h>
  19. #include <exec/memory.h>
  20. #include <exec/io.h>
  21. #include <devices/parallel.h>
  22.  
  23. #include <clib/exec_protos.h>
  24. #include <clib/alib_protos.h>
  25.  
  26. #include <stdio.h>
  27.  
  28. #ifdef LATTICE
  29. int CXBRK(void) { return(0); }  /* Disable SAS CTRL/C handling */
  30. int chkabort(void) { return(0); }  /* really */
  31. #endif
  32.  
  33. void main(void)
  34. {
  35. struct MsgPort  *ParallelMP;          /* Define storage for one pointer */
  36. struct IOExtPar *ParallelIO;         /* Define storage for one pointer */
  37.  
  38. struct IOPArray Terminators =
  39. {
  40. 0x51454125,/* Q E A A */
  41. 0x25252525 /* fill to end with lowest value, must be in descending order */
  42. };
  43.  
  44. UBYTE *WriteBuffer ="abcdefghijklmEopqrstuvwxyze";
  45. UWORD ctr;
  46.  
  47. if (ParallelMP=CreatePort(0,0))
  48.     {
  49.     if (ParallelIO=(struct IOExtPar *)
  50.                     CreateExtIO(ParallelMP,sizeof(struct IOExtPar)) )
  51.         {
  52.         if (OpenDevice(PARALLELNAME,0L,(struct IORequest *)ParallelIO,0) )
  53.             printf("%s did not open\n",PARALLELNAME);
  54.         else
  55.            {
  56.             /* Tell user what we are doing */
  57.             printf("\fLooking for Q, E, A or % in output\n");
  58.  
  59.             /* Set EOF mode flag
  60.              * Set the termination array
  61.              * Send PDCMD_SETPARAMS to the parallel device
  62.              */
  63.             ParallelIO->io_ParFlags |= PARF_EOFMODE;
  64.             ParallelIO->io_PTermArray = Terminators;
  65.             ParallelIO->IOPar.io_Command  = PDCMD_SETPARAMS;
  66.             if (DoIO((struct IORequest *)ParallelIO))
  67.               printf("Set Params failed ");   /* Inform user of error */
  68.             else
  69.              {
  70.              /* Send buffer */
  71.              ParallelIO->IOPar.io_Length   = -1;
  72.              ParallelIO->IOPar.io_Data     = WriteBuffer;
  73.              ParallelIO->IOPar.io_Command  = CMD_WRITE;
  74.              if (DoIO((struct IORequest *)ParallelIO))
  75.               printf("Error: Write failed\n");
  76.              else
  77.              {
  78.                /* Display all characters sent */
  79.                printf("\nThese characters were sent:\n\t\t\tASCII\tHEX\n");
  80.                for (ctr=0;ctr<ParallelIO->IOPar.io_Actual;ctr++)
  81.                     printf("\t\t\t%c\t%x\n",*WriteBuffer,*WriteBuffer++);
  82.                printf("\nThe actual number of characters sent: %d\n",
  83.                          ParallelIO->IOPar.io_Actual);
  84.              }
  85.            }
  86.            CloseDevice((struct IORequest *)ParallelIO);
  87.             }
  88.  
  89.         DeleteExtIO((struct IORequest *)ParallelIO);
  90.         }
  91.     else
  92.         printf("Error: Could not create I/O request\n");
  93.  
  94.     DeletePort(ParallelMP);
  95.     }
  96. else
  97.     printf("Error: Could not create message port\n");
  98. }
  99.