home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / PROGRAM / PCL4C30.ZIP / LOOPBACK.C < prev    next >
Text File  |  1992-01-20  |  1KB  |  65 lines

  1. /*
  2. **        ---  loopback.c ---
  3. **
  4. **   EXAMPLE CODE: Performs loopback test of selected port.
  5. **
  6. **   This example program (not the PCL4C library) is donated to
  7. **   the Public Domain by MarshallSoft Computing, Inc. It is
  8. **   provided as an example of the use of the PCL4C.
  9. **
  10. */
  11.  
  12. #include <stdio.h>
  13. #include "pcl4c.h"
  14.  
  15. #define FALSE 0
  16. #define TRUE !FALSE
  17. #define ESC 0x1b
  18.  
  19. /*** Global Variables ***/
  20.  
  21. int Port;               /* COM port */
  22. int BaudCode = Baud300; /* Code for 300 baud  */
  23. char RxBuf[16];         /* PCL receive buffer  */
  24.  
  25. /*** Main ***/
  26.  
  27. main(argc,argv)
  28. int argc;
  29. char *argv[];
  30. {
  31.  char c;
  32.  int i;
  33.  int Code;
  34.  char *ptr;
  35.  /* get comm port */
  36.  if(argc!=2)
  37.    {printf("Usage: 'LOOPBACK port' where port is 1,2,3, or 4\n");
  38.     exit(1);
  39.    }
  40.  ptr = argv[1];
  41.  if((*ptr<'1')||(*ptr>'4'))
  42.     {printf("COM port must be 1 to 4, not %s\n",ptr);
  43.      exit(1);
  44.     }
  45.  Port = atoi(ptr) - 1;
  46.  printf("LOOPBACK: Testing COM%d -- ",1+Port);
  47.  /* setup receive buffer -- even if don't use it */
  48.  ErrorCheck( SioRxBuf(Port,RxBuf,Size16) );
  49.  /* reset the port */
  50.  ErrorCheck( SioReset(Port,BaudCode) );
  51.  /* do the LOOPBACK test ! */
  52.  Code = SioLoopBack(Port);
  53.  if(Code >= 0) printf("OK");
  54.  else SioError( Code );
  55.  SioDone(Port);
  56. } /* end main */
  57.  
  58. int ErrorCheck(Code)
  59. int Code;
  60. {/* trap PCL error codes */
  61.  if(Code<0)
  62.      {SioError(Code);
  63.       exit(1);
  64.      }
  65. } /* end ErrorCheck */