home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / rkrm.lha / RKRM / Introduction / Pre_V36_Device_Use.c next >
Encoding:
C/C++ Source or Header  |  1992-09-03  |  3.7 KB  |  103 lines

  1. /*
  2.  * Copyright (c) 1992 Commodore-Amiga, Inc.
  3.  * 
  4.  * This example is provided in electronic form by Commodore-Amiga, Inc. for 
  5.  * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  6.  * published by Addison-Wesley (ISBN 0-201-56775-X).
  7.  * 
  8.  * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  9.  * information on the correct usage of the techniques and operating system 
  10.  * functions presented in these examples.  The source and executable code 
  11.  * of these examples may only be distributed in free electronic form, via 
  12.  * bulletin board or as part of a fully non-commercial and freely 
  13.  * redistributable diskette.  Both the source and executable code (including 
  14.  * comments) must be included, without modification, in any copy.  This 
  15.  * example may not be published in printed form or distributed with any
  16.  * commercial product.  However, the programming techniques and support
  17.  * routines set forth in these examples may be used in the development
  18.  * of original executable software products for Commodore Amiga computers.
  19.  * 
  20.  * All other rights reserved.
  21.  * 
  22.  * This example is provided "as-is" and is subject to change; no
  23.  * warranties are made.  All use is at your own risk. No liability or
  24.  * responsibility is assumed.
  25.  *
  26.  *****************************************************************************
  27.  *
  28.  * Pre_V36_Device_Use.c
  29.  *
  30.  * This is an example of using the serial device.
  31.  * First, we will attempt to create a message port with CreatePort()
  32.  * Next, we will attempt to create the IORequest with CreateExtIO()
  33.  * Then, we will attempt to open the serial device with OpenDevice()
  34.  * If successful, we will send the SDCMD_QUERY command to it
  35.  * and reverse our steps.
  36.  * If we encounter an error at any time, we will gracefully exit.
  37.  *
  38.  * Compile with SAS C 5.10  lc -cfistq -v -y -L
  39.  *
  40.  * Run from CLI only
  41.  */
  42.  
  43. #include <exec/types.h>
  44. #include <exec/memory.h>
  45. #include <exec/io.h>
  46. #include <devices/serial.h>
  47.  
  48. #include <clib/exec_protos.h>
  49. #include <clib/alib_protos.h>
  50.  
  51. #include <stdio.h>
  52.  
  53. #ifdef LATTICE
  54. int CXBRK(void) { return(0); }  /* Disable SAS CTRL/C handling */
  55. int chkabort(void) { return(0); }  /* really */
  56. #endif
  57.  
  58. void main(void)
  59. {
  60. struct MsgPort *SerialMP;       /* pointer to our message port */
  61. struct IOExtSer *SerialIO;      /* pointer to our IORequest */
  62.  
  63.     /* Create the message port */
  64. if (SerialMP=CreatePort(NULL,NULL))
  65.     {
  66.         /* Create the IORequest */
  67.     if (SerialIO = (struct IOExtSer *)CreateExtIO(SerialMP,sizeof(struct IOExtSer)))
  68.         {
  69.             /* Open the serial device */
  70.         if (OpenDevice(SERIALNAME,0,(struct IORequest *)SerialIO,0L))
  71.  
  72.             /* Inform user that it could not be opened */
  73.             printf("Error: %s did not open\n",SERIALNAME);
  74.         else
  75.             {
  76.             /* device opened, send query command to it */
  77.             SerialIO->IOSer.io_Command  = SDCMD_QUERY;
  78.             if (DoIO((struct IORequest *)SerialIO))
  79.  
  80.                 /* Inform user that query failed */
  81.                 printf("Query  failed. Error - %d\n",SerialIO->IOSer.io_Error);
  82.             else
  83.                 /* Print serial device status - see include file for meaning */
  84.                 printf("\n\tSerial device status: %x\n\n",SerialIO->io_Status);
  85.  
  86.             /* Close the serial device */
  87.             CloseDevice((struct IORequest *)SerialIO);
  88.             }
  89.         /* Delete the IORequest */
  90.         DeleteExtIO(SerialIO);
  91.         }
  92.     else
  93.         /* Inform user that the IORequest could be created */
  94.         printf("Error: Could create IORequest\n");
  95.  
  96.     /* Delete the message port */
  97.     DeletePort(SerialMP);
  98.     }
  99. else
  100.     /* Inform user that the message port could not be created */
  101.     printf("Error: Could not create message port\n");
  102. }
  103.