How to Use WriteComm() and CloseComm() with FOXTOOLS.FLL

Last reviewed: October 18, 1996
Article ID: Q105011
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5x, 2.6x

SUMMARY

WriteComm() is a function that can be called using FOXTOOLS.FLL in order to write to the COM or LPT ports. CloseComm() is another function that can be called using FOXTOOLS.FLL in order to close the COM or LPT ports. Below are complete descriptions of WriteComm() and CloseComm().

MORE INFORMATION

For information about using the serial port using Visual FoxPro, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q139526
   TITLE     : How to Send to the Serial Port by Using Mscomm32.ocx

WRITECOMM()

Purpose

The WriteComm() function writes to the specified communications device.

Function Syntax

   WriteComm(<comm_id>, <str>, <str_len>)

   Argument       Description
   ----------------------------------------------------------------

   <comm_id>      Specifies the device to receive the bytes. The
                  OpenComm() function returns this value.

   <str>          Points to the buffer that contains the bytes to be
                  written. This is the variable s in the example
                  below.

   <str_len>      Specifies the number of bytes to be written.

Returns

The return value specifies the number of bytes written, if the function is successful. The return value is less than zero if an error occurs, making the absolute value of the return value the number of bytes written.

Comments

For serial ports, the WriteComm() function deletes data in the transmission queue if there is not enough room in the queue for the additional bytes. Applications should use the OpenComm() function to set the size of the transmission queue to an amount no smaller than the size of the largest expected output string.

CLOSECOMM()

Purpose

The CloseComm() function closes the specified communications device and frees any memory allocated for the device's transmission and receiving queues. All characters in the output queue are sent before the communications device is closed.

Function Syntax

   CloseComm(<comm_id>)

   Argument       Description
   -------------------------------------------------------------------

   <comm_id>      Specifies the device to be closed. The OpenComm()
                  function returns this value. In the example below
                  this is the variable com1.

Returns

The return value is zero if the function is successful. Otherwise, it is less than zero.

Code Example

The following code example uses the WriteComm() and CloseComm() functions and FOXTOOLS.FLL to write to and close COM1. (This example can be found in FOXPROW\GOODIES\FOXTOOLS\DIALER.PRG.)

   *-------------------- dialer.prg ------------------------
   * Sample program to output to comm port
   * Uses FoxTools library for generic DLL access

   SET LIBRARY TO SYS(2004)+"foxtools.fll" ADDITIVE

   opencomm = REGFN("OpenComm", "CII", "I")
   writecomm = REGFN("WriteComm", "ICI", "I")
   closecomm = REGFN("CloseComm", "I", "I")

   com1 = CALLFN(opencomm, "COM1:", 100, 100)
   s = "ATDT 5551212" + chr(13)
   =CALLFN(writecomm, com1, s, len(s))

   WAIT WINDOW "Press any key to hang up"
   s = "ATH0" + chr(13)
   =CALLFN(writecomm, com1, s, len(s))

   =CALLFN(closecomm, com1)

   RELEASE LIBRARY SYS(2004)+"foxtools.fll"

REFERENCES

The above information can also be found in the Microsoft Windows Software Development Kit (SDK) "Programmer's Reference Volume 2: Functions" (describes the functions) and the "Programmer's Reference Volume 3: Messages, Structures, and Macros" (describes the returned values). The online Help file for the Professional Version of Visual C++ also contains this information.


Additional reference words: FoxWin 2.50 2.50a 2.50b 2.60 2.60a fll dll
KBCategory: kbtool kbprg kbcode
KBSubcategory: FxprgFoxtools


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 18, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.