home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / cmanual-3.0.lha / CManual / Devices / ParallelDevice / ParallelDevice.doc < prev    next >
Text File  |  1993-10-12  |  48KB  |  1,448 lines

  1. 8    PARALLEL DEVICE
  2.  
  3. 8.1  INTRODUCTION
  4.  
  5. All Amiga models have a parallel port to which you can connect
  6. external devices like a printer, a video digitizer or a sound
  7. sampler. The most common external device for the parallel port
  8. is undoubtedly a printer, although some printers are connected
  9. to the serial device.
  10.  
  11. The parallel port can send and receive eight bits
  12. simultaneously. This can be compared with the serial port which
  13. only can send/receive a stream of bits. The parallel port
  14. is because of this much faster and is therefore often used for
  15. video digitizers or sound samplers.
  16.  
  17. The parallel device helps you to work with the printer at a
  18. very low level, but is still easy to handle. The parallel
  19. device can as the serial device be locked for exclusive access
  20. or you can allow other programs to use the device
  21. simultaneously.
  22.  
  23. It is important to note that the parallel device should only be
  24. used when you want to handle the port directly at a low level.
  25. This can be useful when you want to collect data from a video
  26. digitizer, or send untranslated printer codes. However, if you
  27. simply want to use the printer you should use the printer
  28. device instead. The printer device will automatically take care
  29. of all printer handling, and is using the preference settings.
  30. See next chapter (29) "Printer Device".
  31.  
  32.  
  33.  
  34. 8.2  PARALLEL PORT
  35.  
  36. A parallel port sends a whole byte each time as explained above,
  37. and is therefore very fast. Data that is sent to or received
  38. from the parallel port does not need to be translated in any
  39. way, it is immediately usable.
  40.  
  41. The Amiga's parallel (Centronics) port is a 25-pin D-female-
  42. type connector. (On the old A1000s the parallel port have a
  43. male connector.) Below is an almost complete list of the pin
  44. assignment, together with a short description. (See
  45. illustration "Centronics".)
  46.  
  47.  
  48.   Pin  Name    Direction  Description
  49.   -----------------------------------------------------
  50.     1  STROBE  Out        Used to coordinate the events
  51.     2  Data 0  In/Out     Bit 0
  52.     3  Data 1  In/Out     Bit 1
  53.     4  Data 2  In/Out     Bit 2
  54.     5  Data 3  In/Out     Bit 3
  55.     6  Data 4  In/Out     Bit 4
  56.     7  Data 5  In/Out     Bit 5
  57.     8  Data 6  In/Out     Bit 6
  58.     9  Data 7  In/Out     Bit 7
  59.    10  ACK     In         Data acknowledge
  60.    11  BUSY    In/Out     General Input/Output pin
  61.    12  POUT    In/Out     General Input/Output pin
  62.    13  SEL     In/Out     General Input/Output pin
  63.    14  +5V     -          +5 Volt
  64.    15  NC      In/Out     No connection pin
  65.    16  RESET   Out        The system resets
  66.    17  GND     -          Signal ground
  67.    18  GND     -          Signal ground
  68.    19  GND     -          Signal ground
  69.    20  GND     -          Signal ground
  70.    21  GND     -          Signal ground
  71.    22  GND     -          Signal ground
  72.    23  GND     -          Signal ground
  73.    24  GND     -          Signal ground
  74.    25  GND     -          Signal ground
  75.  
  76.  
  77.  
  78. 8.3  PARALLEL DEVICE
  79.  
  80. The parallel device is very similar to the serial device. It
  81. can either be used in exclusive mode, or several programs may
  82. use the port simultaneously, shared access. When you want that
  83. the parallel device to do something you simply send an already
  84. initialized request block (struct IOExtPar), and the device
  85. will send a message to the reply port when the request has been
  86. done. Exactly as all other devices.
  87.  
  88.  
  89.  
  90. 8.3.1  THE PARALLEL REQUESTBLOCK
  91.  
  92. The request block you should use with the parallel device look
  93. like this: (defined in header file "devices/parallel.h")
  94.  
  95. struct IOExtPar
  96. {
  97.   struct IOStdReq IOPar;
  98.   ULONG io_PExtFlags;
  99.   UBYTE io_Status;
  100.   UBYTE io_ParFlags;
  101.   struct IOPArray io_PTermArray;
  102. };
  103.  
  104. IOPar:         This is the standard request block. The IOStdReq
  105.                structure is defined in header file "exec/io.h",
  106.                and is fully documented in chapter 17 "Devices". 
  107.  
  108. io_PExtFlags:  This is currently not used, but will maybe be
  109.                used in the future when more parallel flags are
  110.                needed. 
  111.  
  112. io_Status:     The status of the parallel port and parallel
  113.                device. There exist for the moment four
  114.                status flags:
  115.                
  116.                  IOPTF_RWDIR    If this flag is set the device
  117.                                 is currently writing to the
  118.                                 parallel device. On the other
  119.                                 hand, if the flag is not set
  120.                                 the device is collecting data
  121.                                 at the parallel port. 
  122.  
  123.                  IOPTF_PARSEL   Printer selected.
  124.  
  125.                  IOPTF_PAPEROUT The printer ran out of paper.
  126.                                 Inform the user!
  127.  
  128.                  IOPTF_PARBUSY  The parallel port is currently
  129.                                 busy.
  130.                                 
  131.                Use the command "PDCMD_QUERY" before you look at
  132.                these fields to make sure everything is up to
  133.                date. 
  134.  
  135. io_ParFlags:   This field contains all special parallel flags.
  136.                There exist only three flags for the moment, and
  137.                one of these is still not usable. Here is the
  138.                complete list:
  139.  
  140.                  PARF_SHARED     Set this flag if you want to
  141.                                  share the parallel port with
  142.                                  other programs. Note that this
  143.                                  flag should only be altered
  144.                                  before you have opened the
  145.                                  parallel device, and should
  146.                                  NOT be changed later on.
  147.                                 
  148.                                  If you want to change status
  149.                                  you should close the parallel
  150.                                  device, alter the status and
  151.                                  then try to open the device
  152.                                  again.
  153.  
  154.                  PARF_RAD_BOOGIE This flag is currently not
  155.                                  used. It is supposed to be
  156.                                  set when you want to send/
  157.                                  receive data at a very high
  158.                                  speed.
  159.  
  160.                  PARF_EOFMODE    This is actually the only
  161.                                  flag you may alter after you
  162.                                  have opened the device. If
  163.                                  the flag is set the parallel
  164.                                  device will immediately
  165.                                  stop the transmission of data
  166.                                  when it finds one of the
  167.                                  specified end-of-file
  168.                                  characters.
  169.  
  170. io_PTermArray: This field contains eight characters which will
  171.                be treated as the end-of-file characters if the 
  172.                PARF_EOFMODE flag is set.
  173.  
  174.  
  175.  
  176. 8.3.2  OPEN THE PARALLEL DEVICE
  177.  
  178. As with all devices you have to open a message port through
  179. which the parallel device can communicate with you, and
  180. allocate a request block (a IOExtPar structure), before you
  181. may open the device itself.
  182.  
  183.   1. Open a message port: (Since it is only our task and the
  184.      device that will use the message port, we do not need
  185.      to make it "public", hence no name. Priority should as
  186.      usual be set to 0, normal priority.)
  187.  
  188.      struct MsgPort *replymp;
  189.  
  190.      replymp = (struct MsgPort *)
  191.        CreatePort( NULL, 0 );
  192.  
  193.      if( !replymp )
  194.        clean_up( "Could not create the reply port!" );
  195.  
  196.  
  197.   2. Allocate a request block of type IOExtPar structure.
  198.      (The IOExtPar structure is an extended version of the
  199.      normal request block, and should therefore be allocated
  200.      with help of the CreateExtIO() function with the size
  201.      set to sizeof( struct IOExtPar ).
  202.  
  203.      struct IOExtPar *parallel_req;
  204.  
  205.      parallel_req = (struct IOExtPar *)
  206.        CreateExtIO( replymp, sizeof( struct IOExtPar ) );
  207.  
  208.      if( !parallel_req )
  209.        clean_up( "Not enough memory!" );
  210.  
  211.  
  212. Once the message port and the request block have successfully
  213. been created, you need to decide if you want exclusive or
  214. shared access. If you want shared access, other programs may
  215. also