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

  1. /*
  2.  * Pre_V36_Device_Use.c
  3.  *
  4.  * This is an example of using the serial device.
  5.  * First, we will attempt to create a message port with CreatePort()
  6.  * Next, we will attempt to create the I/O request with CreateExtIO()
  7.  * Then, we will attempt to open the serial device with OpenDevice()
  8.  * If successful, we will send the SDCMD_QUERY command to it
  9.  * and reverse our steps.
  10.  * If we encounter an error at any time, we will gracefully exit.
  11.  *
  12.  * Compile with SAS C 5.10  lc -cfistq -v -y -L
  13.  *
  14.  * Run from CLI only
  15.  */
  16.  
  17. #include <exec/types.h>
  18. #include <exec/memory.h>
  19. #include <exec/io.h>
  20. #include <devices/serial.h>
  21.  
  22. #include <clib/exec_protos.h>
  23. #include <clib/alib_protos.h>
  24.  
  25. #include <stdio.h>
  26.  
  27. #ifdef LATTICE
  28. int CXBRK(void) { return(0); }     /* Disable SAS CTRL/C handling */
  29. int chkabort(void) { return(0); }  /* really */
  30. #endif
  31.  
  32. void main(void)
  33. {
  34. struct MsgPort *SerialMP;       /* pointer to our message port */
  35. struct IOExtSer *SerialIO;      /* pointer to our I/O request */
  36.  
  37.     /* Create the message port */
  38. if (SerialMP=CreatePort(NULL,NULL))
  39.     {
  40.         /* Create the I/O request */
  41.     if (SerialIO = (struct IOExtSer *)CreateExtIO(SerialMP,sizeof(struct IOExtSer)))
  42.         {
  43.             /* Open the serial device */
  44.         if (OpenDevice(SERIALNAME,0,(struct IORequest *)SerialIO,0L))
  45.  
  46.             /* Inform user that it could not be opened */
  47.             printf("Error: %s did not open\n",SERIALNAME);
  48.         else
  49.             {
  50.             /* device opened, send query command to it */
  51.             SerialIO->IOSer.io_Command  = SDCMD_QUERY;
  52.             if (DoIO((struct IORequest *)SerialIO))
  53.  
  54.                 /* Inform user that query failed */
  55.                 printf("Query  failed. Error - %d\n",SerialIO->IOSer.io_Error);
  56.             else
  57.                 /* Print serial device status - see include file for meaning */
  58.                 printf("\n\tSerial device status: %x\n\n",SerialIO->io_Status);
  59.  
  60.             /* Close the serial device */
  61.             CloseDevice((struct IORequest *)SerialIO);
  62.             }
  63.         /* Delete the I/O request */
  64.         DeleteExtIO(SerialIO);
  65.         }
  66.     else
  67.         /* Inform user that the I/O request could be created */
  68.         printf("Error: Could create I/O request\n");
  69.  
  70.     /* Delete the message port */
  71.     DeletePort(SerialMP);
  72.     }
  73. else
  74.     /* Inform user that the message port could not be created */
  75.     printf("Error: Could not create message port\n");
  76. }
  77.