home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1996 October / PCO_10.ISO / filesbbs / bsrc_260.arj / INCLUDE.ZIP / maxcomm.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-20  |  16.0 KB  |  457 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*            This header file was written by Peter Fitzsimmons             */
  13. /*                                                                          */
  14. /*       OS/2 MAXCOMM.DLL Communications definitions for BinkleyTerm        */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /*
  45.  *  Header file for COMM.DLL,  a high performance multithreading
  46.  *  library for OS/2 serial port i/o.
  47.  *
  48.  *  Copyright (C) 1990 A:WARE Inc.  All rights reserved.
  49.  *
  50.  * Comm.h, and Comm.dll may be used and distributed freely for
  51.  * non-profit use, provided that they are distributed together and
  52.  * are not modified in any way. This means that any program that uses
  53.  * them has to be free, unless prior written persmission from A:WARE
  54.  * Inc. states otherwise.
  55.  *
  56.  * Inclusion with a for-profit/commercial program requires that you
  57.  * purchase the source code for Comm.dll.  No royalties.  The cost is US$199.
  58.  *
  59.  * Contact A:WARE Inc:
  60.  *
  61.  * P.O. Box 670
  62.  * Adelaide St. Postal Station.
  63.  * Toronto, Canada
  64.  * M5C 2J8
  65.  *
  66.  * (416)858-3222.
  67.  *
  68.  * Author: Peter Fitzsimmons, March 1990.
  69.  */
  70.  
  71. /*
  72.  * include os2.h or os2def.h before this file for best results.
  73.  *
  74.  */
  75.  
  76. #ifndef APIENTRY
  77. #include <os2def.h>
  78. #include <bsedos.h>
  79. #endif
  80.  
  81. typedef SHANDLE HCOMM;
  82.  
  83. #ifdef __IBMC__
  84. #define COMMAPI  _Far16 _Pascal
  85. #define LPHCOMM HCOMM * _Seg16
  86. #define LOADDS
  87. #define HCFILE USHORT
  88. #endif
  89.  
  90. #ifdef _MSC_VER
  91. #define COMMAPI  pascal far
  92. #define _Far16
  93. #define _Seg16
  94. #define LPHCOMM HCOMM FAR *
  95. #define LOADDS _loadds
  96. #define HCFILE USHORT
  97. #endif
  98.  
  99. #ifdef __BORLANDC__
  100. #define COMMAPI  _Far16 _Pascal
  101. #define LPHCOMM HCOMM * _Seg16
  102. #define LOADDS
  103. #define HCFILE USHORT
  104. #endif
  105.  
  106. #if defined(__WATCOMC__) /* Watcom 9.5, thanks SJD */
  107. #ifdef __FLAT__
  108. #define COMMAPI  _Far16 _Pascal
  109. #define LPHCOMM HCOMM *
  110. #define LOADDS
  111. #define HCFILE USHORT
  112. #define _Seg16
  113. #else /* __FLAT__ */
  114. #define COMMAPI  pascal far
  115. #ifdef _Far16
  116. #undef _Far16
  117. #endif
  118. #define _Far16
  119. #define _Seg16
  120. #define LPHCOMM HCOMM FAR *
  121. #define LOADDS _loadds
  122. #define HCFILE USHORT
  123. #endif /* __FLAT__ */
  124. #endif /* __WATCOMC__ */
  125.  
  126.  
  127. #if !defined(_QC) && !defined(__IBMC__)
  128. #pragma comment(lib, "maxcomm.lib")
  129. #endif
  130.  
  131. extern HCOMM hcModem;            /* Moved here  WRA */
  132.  
  133. /*
  134.  * open comm device.  return 0 if successful,  OS/2 error if not.
  135.  *
  136.  * This function (or ComHRegister()) must be called before any
  137.  * other Com() function.
  138.  *
  139.  * Do not use this function if the port handle has been inherited from
  140.  * another process (use ComHRegister() instead).
  141.  *
  142.  * The comm handle (placed in pHcomm) is not a file handle,  and should
  143.  * not be used by Dos() functions.  If the file handle to the port is
  144.  * needed (to pass to a child process),  use the ComGetFH() function.
  145.  *
  146.  * If RxBufSize and/or TxBufSize are/is zero,  a default size is used.
  147.  *
  148.  
  149.   When using COM0x.SYS,  the default buffer size is the same as the
  150.   buffer size used by COM0x.SYS.  For Tx, this is the optimum size
  151.   to keep COM0x.SYS busy.  A buffer larger than this will not gain
  152.   any extra performance.  Therefore, the common urge to make the
  153.   transmit buffer large will not have the desired effect.  If there
  154.   was some way to make the REAL transmit buffer (the one in
  155.   COM0x.SYS) larger,  performance gains WOULD be seen,  but there is
  156.   no way to do this unless you have the source code for COM0x.SYS.
  157.   If you DO have the source (in the DDK), and you increase the
  158.   buffer sizes, use 0 for the XxBufSize and ComOpen will use your
  159.   larger buffers (ComOpen/Register uses the standard IOCTL call to
  160.   query the buffer sizes).
  161.  
  162.   RxBufSize, on the otherhand, does not affect performance of any
  163.   functions in the Com() module.  To avoid overflows however,  you
  164.   should set this to at least the size of the COM0x.SYS Rx buffer,
  165.   or use 0 so the default size if selected.  When the Rx buffer gets
  166.   full,  the speaker will sound (DosBeep(200, 10)).  There are two
  167.   solutions to this problem:  Make the Rx buffer larger (preferred),
  168.   or raise the priority of the thread calling ComRead()/ComGetc().
  169.  
  170.   All threads created by comm.dll run at the default priority. Since
  171.   com0?.sys is interrupt driven,  Reading/Writing to it at a high
  172.   priorty does not improve anything.  If the Rx thread is starved
  173.   for such a long time that com0?.sys buffer gets full,  it means
  174.   some other process on your computer is badly behaved (IT is
  175.   problably running at Time Critical class when it shouldn't be).
  176.   There are four ways to solve this (in order of preference):
  177.  
  178.   1) Insert DosSleep(1L) in the polling loops that are guilty (this
  179.   assumes you have source code), and/or have it run at NORMAL
  180.   priority class.
  181.  
  182.   2) decrease MAXWAIT in config.sys.
  183.  
  184.   3) Prior to calling ComOpen/ComHRegister, raise the priorty of the
  185.   current thread (or of the whole process).  The Rx/Tx threads will
  186.   inherhit this priority.
  187.  
  188.   4) set PRIORITY=ABSOLUTE in config.sys.
  189.  
  190.  
  191.   FYI:  OS/2 1.2 uses a default size of 1024 bytes for Rx, and 128
  192.         bytes for Tx.
  193.  
  194.  *
  195.  *
  196.  */
  197.  
  198. USHORT COMMAPI ComOpen (PSZ _Seg16 PortName,
  199.     LPHCOMM pHcomm,            /* pointer to var for Comm handle */
  200.     USHORT RxBufSize,            /* desired size of Receive queue*/
  201.     USHORT TxBufSize);        /* desired size of Transmit queue */
  202.  
  203. /*
  204.  * ComHRegister():  Register a comm handle opened by another process.
  205.  *
  206.  * This function (or ComOpen()) must be called before any
  207.  * other Com() function.
  208.  */
  209.  
  210. USHORT COMMAPI LOADDS ComHRegister (HCFILE hf,
  211.     LPHCOMM * pHcomm,            /* pointer to var for Comm handle */
  212.     USHORT RxBufSize,            /* desired size of receive queue*/
  213.     USHORT TxBufSize);        /* desired size of xmit queue */
  214.  
  215. /* ComClose():  Close and/or DeRegister comm handle.
  216.  *
  217.  * This function will not DosClose() the handle if the handle was not
  218.  * opened by this process with ComOpen() (ie: If ComHRegister() was used,
  219.  * ComClose() will not DosClose() the handle.  ComClose() must still be
  220.  * called though).
  221.  */
  222.  
  223. USHORT COMMAPI ComClose (HCOMM hcomm);
  224.  
  225. /*
  226.  * return TRUE if the device (comx, named pipe, etc) is considered
  227.  * in an "Online" state.
  228.  */
  229.  
  230. USHORT COMMAPI ComIsOnline (HCOMM hcomm);
  231.  
  232. /*
  233.  * ComWrite(): Place many bytes in output queue.
  234.  *
  235.  * This function does not return until all of the bytes have been
  236.  * placed in the output queue,  or an error occurs.
  237.  *
  238.  * If the device becomes offline while this function is waiting for
  239.  * queue space, and the watchdog feature is enabled (see
  240.  * ComWatchDog()),  this function returns before completion.
  241.  *
  242.  */
  243.  
  244. USHORT COMMAPI ComWrite (
  245.     HCOMM hc,                    /* file handle                   */
  246.     PVOID _Seg16 pvBuf,        /* pointer to buffer             */
  247.     USHORT cbBuf);                /* number of bytes to write      */
  248.  
  249. /*
  250.  * ComRead(): Read many bytes from input queue.
  251.  *
  252.  * This function will copy bytes from the input queue to pvBuf,
  253.  * until the input queue is empty, or 'cbBuf' bytes have been copied.
  254.  *
  255.  *
  256.  */
  257.  
  258. USHORT COMMAPI ComRead (
  259.     HCOMM hc,                    /* file handle                 */
  260.     PVOID _Seg16 pvBuf,        /* pointer to buffer           */
  261.     USHORT cbBuf,                /* maximum bytes to read       */
  262.     PUSHORT _Seg16 pcbBytesRead);    /* pointer to variable receiving byte count */
  263.  
  264. /*
  265.  * ComGetc() : return next byte in input queue,  or -1 if there is none.
  266.  */
  267.  
  268. SHORT COMMAPI ComGetc (HCOMM hc);
  269.  
  270. /*
  271.  * ComPeek():  the same as ComGetc(),  but the character is left in the
  272.  * input queue.
  273.  */
  274.  
  275. SHORT COMMAPI ComPeek (HCOMM hc);
  276.  
  277. /*
  278.  * ComPutc():  Place one byte in output queue.  This function does not
  279.  * return until the byte is placed in the output queue, or an error occurs.
  280.  *
  281.  * If the device becomes offline while this function is waiting for
  282.  * queue space, and the watchdog feature is enabled (see
  283.  * ComWatchDog()),  this function returns before completion.
  284.  */
  285.  
  286. USHORT COMMAPI ComPutc (HCOMM hc, SHORT c);
  287.  
  288. /*
  289.  * ComRxWait():  Wait for something to be placed into the input queue.
  290.  *
  291.  * If lTimeOut is -1L,  wait forever.  Otherwise, lTimeOut is the
  292.  * number of milliseconds to wait (or 0) before returning a timeout
  293.  * error (ERROR_SEM_TIMEOUT).
  294.  *
  295.  * If the device becomes offline while this function is waiting, and
  296.  * the watchdog feature is enabled (see ComWatchDog()),  this
  297.  * function returns before completion.
  298.  *
  299.  */
  300.  
  301. USHORT COMMAPI ComRxWait (HCOMM hc, LONG lTimeOut);
  302.  
  303. /*
  304.  * ComTxWait():  Wait for output queue to empty.
  305.  *
  306.  * If lTimeOut is -1L,  wait forever.  Otherwise, lTimeOut is the
  307.  * number of milliseconds to wait (or 0) before returning a timeout
  308.  * error (ERROR_SEM_TIMEOUT).
  309.  *
  310.  * If the device becomes offline while this function is waiting, and
  311.  * the watchdog feature is enabled (see ComWatchDog()),  this
  312.  * function returns before completion.
  313.  */
  314.  
  315. USHORT COMMAPI ComTxWait (HCOMM hc, LONG lTimeOut);
  316.  
  317. /*
  318.  * return number of bytes in input queue.
  319.  *
  320.  */
  321.  
  322. USHORT COMMAPI ComInCount (HCOMM hc);
  323.  
  324. /*
  325.  * return number of bytes in output queue.
  326.  *
  327.  */
  328.  
  329. USHORT COMMAPI ComOutCount (HCOMM hc);
  330.  
  331. /*
  332.  * return space in output queue.
  333.  *
  334.  */
  335.  
  336. USHORT COMMAPI ComOutSpace (HCOMM hc);
  337.  
  338. #define COMM_PURGE_RX 1
  339. #define COMM_PURGE_TX 2
  340. #define COMM_PURGE_ALL  (COMM_PURGE_RX | COMM_PURGE_TX)
  341.  
  342. /*
  343.  * ComPurge():  Purge (discard) i/o queue(s).
  344.  *
  345.  *  Where fsWhich is a combination of :
  346.  *           COMM_PURGE_RX      Purge input queue.
  347.  *
  348.  *           COMM_PURGE_TX      Purge output queue.
  349.  */
  350.  
  351. USHORT COMMAPI ComPurge (HCOMM hc, SHORT fsWhich);
  352.  
  353. /*
  354.  * ComPause():
  355.  *
  356.  * This function causes the Rx and Tx threads to end, after all
  357.  * Tx activity has ended.  Any bytes still in the Rx queue are
  358.  * purged.  After calling this function,  it is safe for other
  359.  * processes to use the comm port file handle (see ComGetFH()).
  360.  *
  361.  */
  362.  
  363. USHORT COMMAPI ComPause (HCOMM hc);
  364.  
  365. /*
  366.  * ComResume():
  367.  *
  368.  * This function creates new Rx and Tx threads,  and resets the state
  369.  * of the comm port to what is was when ComPause() was called.
  370.  *
  371.  * It is an error to call this function without calling ComPause().
  372.  *
  373.  */
  374.  
  375. USHORT COMMAPI ComResume (HCOMM hc);
  376.  
  377. /*
  378.  *
  379.  * ComGetFH():  get the short handle (SHANDLE) the comm module is
  380.  * using.
  381.  *
  382.  * If the comm routines were initialized with ComHRegister(),  the
  383.  * handle returned by this function will be the same handle passed
  384.  * to ComHRegister().
  385.  *
  386.  * NOTE: Programs must not use this handle with any file system
  387.  * calls (DosRead, DosWrite, DosClose, etc).  It may be used with
  388.  * DosDevIOCTL() to query device dependant info.
  389.  *
  390.  * The intended use for this function is so that one process can
  391.  * pass the file handle to another process.  Don't forget to
  392.  * call ComPause() before spawning another process that uses the comm
  393.  * port.
  394.  */
  395.  
  396. HCFILE COMMAPI ComGetFH (HCOMM hc);
  397.  
  398. /*
  399.  * ComWatchDog():  Enable/disable the "online" watchdog.
  400.  *
  401.  * When the watchdog is enabled,  and the state of the comm handle
  402.  * is no longer "online" (in the case of a modem,  the carrier has dropped),
  403.  * any Com functions that are blocked (ComRxWait, ComTxWait) become
  404.  * unblocked,  within the period specified by the "Seconds" paramater.
  405.  *
  406.  * It is up to the application to notice that the device is no longer
  407.  * online,  after the blocked Com function returns.
  408.  *
  409.  * Obviously,  one must remember to disable the watchdog feature between
  410.  * phone calls.
  411.  *
  412.  * When a device is first initialized by the comm moduel (via ComOpen() or
  413.  * ComHRegister()) the watchdog feature is disabled.
  414.  *
  415.  * The "Seconds" paramater is ignored unless "OnOff" is TRUE.
  416.  *
  417.  * If "OnOff" is TRUE,  and "Seconds" is 0,  the current watchdog period
  418.  * is used.  When first initialized,  the watchdog period is 3 seconds.
  419.  */
  420.  
  421. USHORT COMMAPI ComWatchDog (HCOMM hc, BOOL OnOff, USHORT Seconds);
  422.  
  423. /*******************************************************************
  424.  *                                                                 *
  425.  * Thus far, all functions listed are applicable to many           *
  426.  * device types,  including named pipes.  The 3 functions          *
  427.  * that follow, however, are specific to COM0x.SYS (rs232c ports). *
  428.  *                                                                 *
  429.  *******************************************************************/
  430.  
  431. /*
  432.  * Get/Set DBC.  See os/2 docs on "DCBINFO", used in a
  433.  * DosIOCTL(ASYNC_GETDCBINFO) call (ioctl category 1, function 73h)
  434.  *
  435.  *
  436.  * NOTE: ComSetDCB() ignores bits 0, 1 and 2 of the "fbTimeout"
  437.  * field of the DCBINFO structure. (if you are using the IBM toolkit,
  438.  * this is called "flags3" of the DCB).  These bits control the type
  439.  * of read timeout processing, and write timeout processing that the
  440.  * com01.sys device driver uses.  The Com() api insists that
  441.  * "write infinite timeout processing" NOT be enabled,  and
  442.  * "Wait-for-something read timeout processing" be in effect, so this
  443.  * function overrides the above mentioned bits to ensure this.
  444.  *
  445.  */
  446.  
  447. #ifdef IOCTL_ASYNC
  448. USHORT COMMAPI ComGetDCB (HCOMM hc, PDCBINFO _Seg16 pdbc);
  449. USHORT COMMAPI ComSetDCB (HCOMM hc, PDCBINFO _Seg16 pdcb);
  450. #endif
  451.  
  452. USHORT COMMAPI ComSetBaudRate (HCOMM hcomm,
  453.     LONG bps,
  454.     CHAR parity,
  455.     USHORT databits,
  456.     USHORT stopbits);
  457.