home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / examples / example_device / driver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-24  |  1.2 KB  |  43 lines

  1. /* Driver program to test example.device */
  2. /* Copyright (c) 1993 SAS Institute, Inc, Cary, NC, USA */
  3. /* All Rights Reserved */
  4.  
  5. #include <exec/devices.h>
  6. #include <devices/serial.h>
  7. #include <proto/exec.h>
  8.  
  9. void main(void)
  10. {
  11.     struct IOExtSer *ior;
  12.     struct MsgPort *SerialMP;
  13.     char buff[10];
  14.  
  15.     if (SerialMP = CreatePort(0,0))
  16.     {
  17.         if (ior = (struct IOExtSer *) 
  18.                        CreateExtIO(SerialMP, sizeof(struct IOExtSer)))
  19.         {
  20.             if (OpenDevice("example.device",-1,(struct IORequest*)ior,0) == 0)
  21.             {
  22.                 ior->IOSer.io_Data = buff;
  23.                 while(1)
  24.                 {
  25.                     ior->IOSer.io_Command = CMD_READ;
  26.                     ior->IOSer.io_Length = 1;
  27.                     DoIO((struct IORequest *)ior);
  28.                     if (ior->IOSer.io_Actual < 1)
  29.                     {
  30.                         CloseDevice((struct IORequest *)ior);
  31.                         break;
  32.                     }
  33.                     ior->IOSer.io_Command = CMD_WRITE;
  34.                     ior->IOSer.io_Length = 1;
  35.                     DoIO((struct IORequest *)ior);
  36.                 }
  37.             }
  38.             DeleteExtIO((struct IORequest *)ior);
  39.         }
  40.         DeletePort(SerialMP);
  41.     }
  42. }
  43.