home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / SOFTWARE / LIBS / PCL4C43.ZIP / DOOR.C (.txt) < prev    next >
Text File  |  1995-03-29  |  3KB  |  104 lines

  1. /*
  2. **   DOOR.C  (3/3/95)
  3. **
  4. **   EXAMPLE CODE: Gain control w/o resetting UART.
  5. **
  6. **   (1) Start your communications program such as PROCOMM
  7. **   (2) Select "DOS gateway" to get the DOS prompt.
  8. **   (3) Start this program. You will gain control of the
  9. **       COM port without resetting the UART or dropping the
  10. **       modem carrier.
  11. **   (4) When done, exit this program, then type EXIT to
  12. **       return to MSDOS.
  13. **
  14. **   For more information, see documentation.
  15. **
  16. **   This example program (not the PCL4C library) is donated to
  17. **   the Public Domain by MarshallSoft Computing, Inc. It is
  18. **   provided as an example of the use of the PCL4C.
  19. **
  20. */
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <malloc.h>
  25. #include <dos.h>
  26. #include <string.h>
  27. #include "pcl4c.h"
  28.  
  29. #define FALSE 0
  30. #define TRUE !FALSE
  31. #define CTLZ    0x1a
  32. #define BUFSIZE 64
  33.  
  34. /*** Global Variables ***/
  35.  
  36. int Port;
  37.  
  38. /*** locol prototypes ***/
  39.  
  40. void ErrorCheck(int);
  41. int AllocSeg(int);
  42.  
  43. /*** Main ***/
  44.  
  45. void main(int argc,char *argv[])
  46. {char c;
  47.  char *ptr;
  48.  int i, rc;
  49.  /* get comm port */
  50.  if(argc!=2)
  51.    {printf("Usage: 'DOOR <port>' \n");
  52.     exit(1);
  53.    }
  54.  /* get port number from command line */
  55.  Port = atoi(argv[1]) - 1;
  56.  if((Port<COM1) || (Port>COM20))
  57.      {printf("Port must be COM1 to COM20n");
  58.       exit(1);
  59.      }
  60.  printf("DOOR: COM%d\n",1+Port);
  61.  /* setup receive buffer */
  62.  ErrorCheck( SioRxBuf(Port,AllocSeg(64),Size64) );
  63.  /* take over the port */
  64.  ErrorCheck( SioReset(Port,NORESET) );
  65.  /* DTR & RTS will be the same as before calling SioReset */
  66.  printf("Enter terminal loop ( COM%d )\n",1+Port);
  67.  printf("Type ^Z to quit !\n");
  68.  /* enter terminal loop */
  69.  while(TRUE)
  70.      {/* was key pressed ? */
  71.       if(SioKeyPress())
  72.           {i = SioKeyRead();
  73.            if((char)i==CTLZ)
  74.               {/* restore COM port status & exit */
  75.                SioDone(Port);
  76.                exit(1);
  77.               }
  78.            else SioPutc(Port,(char)i);
  79.           } /* end if */
  80.       /* any incoming over serial port ? */
  81.       i = SioGetc(Port,0);
  82.       if(i>-1) SioCrtWrite((char)i);
  83.      } /* end while */
  84. } /* end main */
  85.  
  86. void ErrorCheck(int Code)
  87. {/* trap PCL error codes */
  88.  if(Code<0)
  89.      {SioError(Code);
  90.       exit(1);
  91.      }
  92. } /* end ErrorCheck */
  93.  
  94. int AllocSeg(int Size)
  95. {int Seg;
  96.  char far *Ptr;
  97.  /* allocate far heap */
  98.  Ptr = (char far *) _fmalloc(Size+16);
  99.  if(Ptr==NULL) return 0;
  100.  /* SEG:0 points to buffer */
  101.  Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
  102.  return Seg;
  103. }
  104.