home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / SOFTWARE / LIBS / PCL4C43.ZIP / SIMPLE.C (.txt) < prev    next >
Text File  |  1995-04-02  |  2KB  |  97 lines

  1. /*
  2. **  simple.c (4/2/95)
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <malloc.h>
  8. #include <dos.h>
  9. #include <string.h>
  10. #include "pcl4c.h"
  11.  
  12. #define FALSE 0
  13. #define TRUE !FALSE
  14.  
  15. /*** Global Variables ***/
  16.  
  17. int Port = COM1;          /* Port COM1 */
  18. int BaudCode;             /* baud rate code ( index into BaudRate[] ) */
  19. char *BaudRate[10] =  {"300","600","1200","2400","4800","9600",
  20.                        "19200","38400","57600","115200"};
  21.  
  22. /*** local prototypes */
  23.  
  24. int BaudMatch(char *);
  25. int ErrorCheck(int);
  26.  
  27. /*** main ***/
  28.  
  29. void main(int argc, char *argv[])
  30. {char c;
  31.  int  i, rc;
  32.  char far *Ptr;
  33.  int  Seg;
  34.  if(argc!=3)
  35.    {printf("Usage: SIMPLE <port> <baud>\n");
  36.     exit(1);
  37.    }
  38.  /* get port number from command line */
  39.  Port = atoi(argv[1]) - 1;
  40.  if((Port<COM1) || (Port>COM20))
  41.      {printf("Port must be COM1 to COM20n");
  42.       exit(1);
  43.      }
  44.  /* get baud rate from command line */
  45.  BaudCode = BaudMatch(argv[2]);
  46.  if(BaudCode<0)
  47.      {printf("Cannot recognize baud rate = %s\n",argv[2]);
  48.       exit(1);
  49.      }
  50.  /* setup 128 byte receive buffer */
  51.  Ptr = (char far *) _fmalloc(128+16);
  52.  Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
  53.  SioRxBuf(Port,Seg,Size128);
  54.  /* set port parmameters */
  55.  ErrorCheck( SioParms(Port,NoParity,OneStopBit,WordLength8) );
  56.  /* reset the port */
  57.  ErrorCheck( SioReset(Port,BaudCode) );
  58.  /* set DTR and RTS */
  59.  ErrorCheck( SioDTR(Port,'S') );
  60.  ErrorCheck( SioRTS(Port,'S') );
  61.  printf("Enter terminal loop ( Type ^Z to exit )\n");
  62.  /* enter terminal loop */
  63.  while(TRUE)
  64.      {/* was key pressed ? */
  65.       if(SioKeyPress())
  66.           {i = SioKeyRead();
  67.            if((char)i==0x1a)
  68.               {/* restore COM port status & exit */
  69.                SioDone(Port);
  70.                exit(1);
  71.               }
  72.            else SioPutc(Port,(char)i);
  73.           } /* end if */
  74.       /* any incoming over serial port ? */
  75.       i = SioGetc(Port,0);
  76.       if(i>-1) SioCrtWrite((char)i);
  77.      } /* end while */
  78. } /* end main */
  79.  
  80. int ErrorCheck(int Code)
  81. {/* trap PCL error codes */
  82.  if(Code<0)
  83.      {SioError(Code);
  84.       SioDone(Port);
  85.       exit(1);
  86.      }
  87.  return(0);
  88. } /* end ErrorCheck */
  89.  
  90.  
  91. int BaudMatch(char *P)
  92. {int i;
  93.  /* find baud rate in table */
  94.  for(i=0;i<10;i++) if(strcmp(BaudRate[i],P)==0) return(i);
  95.  return(-1);
  96. }
  97.