home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / DUMBMODE.ZIP / DUMBMODE.C next >
C/C++ Source or Header  |  1991-03-14  |  3KB  |  110 lines

  1. /*
  2.  
  3.   DUMBMODE.C
  4.  
  5.   Simple program to set comm port mode before invoking BinkleyTerm under
  6.   OS/2 2.0 with Gary Rosema's com16550.sys
  7.  
  8.   Communications parameters for COM1 are set to 19200 baud,
  9.   8 data bits, no parity, and 1 stop bit.
  10.  
  11.   Usage is:  dumbmode
  12.  
  13.   Released to the public domain by John Tarbox (FidoNet 1:150/130.0)
  14. */
  15.  
  16. #define INCL_BASE
  17. #define INCL_DOSDEVIOCTL
  18. #include <os2.h>
  19.  
  20. #include <string.h>
  21. #include <stdio.h>
  22.  
  23. #define PARITY_NONE 0
  24. #define PARITY_ODD 1
  25. #define PARITY_EVEN 2
  26.  
  27. #define ONE_STOP_BIT 0
  28. #define ONEANDAHALF_STOP_BITS 1
  29. #define TWO_STOP_BITS 2
  30.  
  31. #define COMPORT 1
  32.  
  33. int DisplayDCB (void);
  34.  
  35. DCBINFO usDCB;
  36. unsigned chandle;                   /* handle for COM port */
  37.  
  38. int main(void)
  39. {
  40.   USHORT usBaudRate = 19200;
  41.   USHORT usBaudRateOld;
  42.   LINECONTROL lc;
  43.   unsigned action;
  44.   unsigned openflag = 0x01;
  45.   unsigned openmode = 0x12;
  46.   PSZ pszCOMPORT = "com1";
  47.  
  48.   /* open com port */
  49.   if (DosOpen(pszCOMPORT, &chandle, &action, 0L, 0, openflag, openmode, 0L))
  50.       puts("\nCan't open COM device.\n");
  51.  
  52.   if (DosDevIOCtl(&usBaudRateOld, 0L, ASYNC_GETBAUDRATE, 1, chandle))
  53.       puts("\nCan't get baud rate.");
  54.  
  55.   if (DosDevIOCtl(&lc, 0L, ASYNC_GETLINECTRL, 1, chandle))
  56.       puts("\nCan't get line control info.");
  57.  
  58.   printf( "Old baud : %u:%c,%u,%u\n\r",
  59.        usBaudRateOld, lc.bParity, lc.bDataBits, lc.bStopBits );
  60.  
  61.   DisplayDCB();
  62.  
  63.   if (DosDevIOCtl(NULL, &usBaudRate, ASYNC_SETBAUDRATE, 1, chandle))
  64.       puts("\nCan't set baud rate.");
  65.  
  66.   lc.bDataBits = 8;
  67.   lc.bParity   = PARITY_NONE;
  68.   lc.bStopBits = ONE_STOP_BIT;
  69.  
  70.   if (DosDevIOCtl(NULL, &lc, ASYNC_SETLINECTRL, 1, chandle))
  71.       puts("\nCan't configure COM port.");
  72.  
  73.   usDCB.fbCtlHndShake = 8;
  74.   usDCB.fbFlowReplace = 128;
  75.   usDCB.fbTimeout     = 3;
  76.  
  77.   if (DosDevIOCtl(0L, &usDCB, ASYNC_SETDCBINFO, 1, chandle))
  78.       puts("\nCan't set DCB info.");
  79.  
  80.   puts("\nComm port set...");
  81.   DisplayDCB();
  82.   puts("\nTerminating...");
  83.  
  84.   return 0;
  85.  
  86. } /* main */
  87.  
  88. int DisplayDCB()
  89. {
  90.   if (DosDevIOCtl(&usDCB, 0L, ASYNC_GETDCBINFO, 1, chandle))
  91.        {
  92.       puts("\nCan't get dcb info.");
  93.       return 99;
  94.        }
  95.  
  96.     puts( "DCB info : \n\r" );
  97.  
  98.     printf("  Write timeout   : %u\n\r", usDCB.usWriteTimeout);
  99.     printf("  Read  timeout   : %u\n\r", usDCB.usReadTimeout);
  100.     printf("  Handshake       : %u\n\r", usDCB.fbCtlHndShake);
  101.     printf("  Flow replace    : %u\n\r", usDCB.fbFlowReplace);
  102.     printf("  Timeout         : %u\n\r", usDCB.fbTimeout);
  103.     printf("  Error repl. char: %u\n\r", usDCB.bErrorReplacementChar);
  104.     printf("  Break repl. char: %u\n\r", usDCB.bBreakReplacementChar);
  105.     printf("  Xon char        : %u\n\r", usDCB.bXONChar);
  106.     printf("  Xoff char       : %u\n\r", usDCB.bXOFFChar);
  107.  
  108.   return 0;
  109. }
  110.