How to Use WriteComm() and CloseComm() with FOXTOOLS.FLLLast reviewed: October 18, 1996Article ID: Q105011 |
The information in this article applies to:
SUMMARYWriteComm() 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 INFORMATIONFor 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()
PurposeThe 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. ReturnsThe 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.
CommentsFor 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()
PurposeThe 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. ReturnsThe return value is zero if the function is successful. Otherwise, it is less than zero.
Code ExampleThe 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" REFERENCESThe 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |