home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / HDWBUF.ZIP / HDWBUFF.C < prev    next >
C/C++ Source or Header  |  1989-10-13  |  3KB  |  116 lines

  1. /* ----------------------------------------------------------------------
  2. .context BUFFOFF
  3. .category UTILITY
  4. VOID main(INT argv, CHAR *argc[]);
  5.  
  6. Description: 
  7.      A short program that turns off the hardware bufferring of the COMM
  8. port
  9.  
  10. Parameter     Description
  11. -------------------------------------------------------------------------
  12. argv          number of parameters
  13. argc          parms:
  14.               1st parm = commport to change ( COM1: COM2: COM3: ... )
  15.               2nd parm = state to set it too ( ON, OFF );
  16.  
  17. Returns: 
  18.      A fail state to command.com
  19.  
  20. Comments: 
  21.  
  22. References: 
  23.  
  24. See Also: 
  25. .ref 
  26.  
  27. Development History: 
  28.   Date         Programmer          Description of modification   
  29.   10/10/1989   Paul Montgomery     Initial development           
  30. -------------------------------------------------------------------- */
  31. #define INCL_DOSFILEMGR
  32. #define INCL_DOSDEVIOCTL
  33. #define INCL_DOSDEVICES
  34. #include <os2.h>
  35. #include <stdio.h>
  36. #include <string.h>
  37.  
  38. VOID main ( INT argc, CHAR *argv[] )
  39. {
  40.    HFILE hf;
  41.    USHORT usAction;
  42.    DCBINFO   dcb;
  43.  
  44.    if (argc < 3)
  45.       {
  46.       printf("\n\
  47. usage: hdwbuff COM1 ON   ; to turn on hardware buffering for COM1\n");
  48.       printf(
  49. "       hdwbuff COM2 OFF  ; to turn off hardware buffering for COM2\n");
  50.       DosExit(EXIT_PROCESS, 1);
  51.       }
  52.  
  53.    // open the port specified
  54.    DosOpen(argv[1],
  55.       &hf,         
  56.       &usAction,   
  57.       0L,        
  58.       FILE_NORMAL, 
  59.       FILE_OPEN, 
  60.       OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE,
  61.       0L);
  62.  
  63.    if (hf)
  64.       {
  65.       // get the current state of things with that port
  66.       DosDevIOCtl(&dcb,
  67.          NULL,         
  68.          0x73,         
  69.          1,            
  70.          hf);
  71.  
  72.       // figure out what the user wants
  73.       if ((strcmp("ON",argv[2])==0) || (strcmp("on",argv[2]) == 0))
  74.          {
  75.          // change the hardware buffering to ENABLED
  76.          dcb.fbTimeout = dcb.fbTimeout & 0xE7;
  77.          dcb.fbTimeout = dcb.fbTimeout | 0x08;
  78.          printf("\n Extended Hardware Buffering Enabled\n");
  79.          }
  80.       else if ((strcmp("OFF",argv[2])==0) || (strcmp("off",argv[2]) == 0))
  81.          {
  82.          // change the hardware bufferring to DISABLED
  83.          dcb.fbTimeout = dcb.fbTimeout & 0xE7;
  84.          printf("\n Extended Hardware Buffering Disabled\n");
  85.          }
  86.       else
  87.          {
  88.          printf("\navailable options are ON, OFF\n");
  89.          DosClose(hf);
  90.          DosExit(EXIT_PROCESS, 1);
  91.          }
  92.  
  93.       // make the change.
  94.       DosDevIOCtl(NULL,
  95.          &dcb,         
  96.          0x53,         
  97.          1,            
  98.          hf);
  99.  
  100.       // close the port
  101.       DosClose(hf);
  102.       }
  103.    else
  104.       {
  105.       printf("\n The open on %s did not work.",argv[1]);
  106.       printf("\n\
  107. usage: hdwbuff COM1 ON   ; to turn on hardware buffering for COM1\n");
  108.       printf(
  109. "       hdwbuff COM2 OFF  ; to turn off hardware buffering for COM2\n");
  110.       DosExit(EXIT_PROCESS, 1);
  111.  
  112.       }
  113.    DosExit(EXIT_PROCESS, 0);
  114. }
  115.  
  116.