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

  1. /*
  2.  * Query_Serial.c
  3.  *
  4.  * We will try to open the serial device and if unsuccessful,
  5.  * will return the name of the owner.
  6.  *
  7.  * Compile with SAS C 5.10  lc -b1 -cfistq -v -y -L
  8.  *
  9.  * Run from CLI only
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <dos/dos.h>
  15. #include <resources/misc.h>
  16. #include <devices/serial.h>
  17.  
  18. #include <clib/exec_protos.h>
  19. #include <clib/alib_protos.h>
  20. #include <clib/dos_protos.h>
  21. #include <clib/misc_protos.h>
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25.  
  26. #ifdef LATTICE
  27. int CXBRK(void) { return(0); }     /* Disable SAS CTRL/C handling */
  28. int chkabort(void) { return(0); }  /* really */
  29. #endif
  30.  
  31. struct Library *MiscBase;
  32.  
  33. struct MsgPort  *SerialMP;         /* Message port pointer */
  34. struct IOExtSer *SerialIO;         /* I/O request pointer */
  35.  
  36. void main(void)
  37. {
  38. UWORD status;    /* return value of SDCMD_QUERY */
  39. UBYTE *user;     /* name of serial port owner if not us */
  40.  
  41. if (SerialMP=CreatePort(NULL,NULL) )
  42.     {
  43.     if (SerialIO=(struct IOExtSer *)CreateExtIO(SerialMP,sizeof(struct IOExtSer)) )
  44.         {
  45.         if (OpenDevice(SERIALNAME,0L,(struct IORequest *)SerialIO,0))
  46.             {
  47.             printf("\n%s did not open",SERIALNAME);
  48.  
  49.             MiscBase= (struct Library *)OpenResource(MISCNAME);
  50.  
  51.             /* Find out who has the serial device */
  52.             if ((user = AllocMiscResource(MR_SERIALPORT,"Us")) == NULL)
  53.                 {
  54.                 printf("\n");
  55.                 FreeMiscResource(MR_SERIALPORT);
  56.                 }
  57.             else
  58.                 printf(" because %s owns it \n\n",user);
  59.             }
  60.         else
  61.             {
  62.             SerialIO->IOSer.io_Command  = SDCMD_QUERY;
  63.             DoIO((struct IORequest *)SerialIO);             /* execute query */
  64.  
  65.             status = SerialIO->io_Status;                    /* store returned status */
  66.  
  67.             printf("\tThe serial port status is %x\n",status);
  68.  
  69.             CloseDevice((struct IORequest *)SerialIO);
  70.             }
  71.  
  72.         DeleteExtIO(SerialIO);
  73.         }
  74.     else
  75.         printf("Can't create I/O request\n");
  76.  
  77.     DeletePort(SerialMP);
  78.     }
  79. else
  80.     printf("Can't create message port\n");
  81. }
  82.