Microsoft KB Archive/105011

{|
 * width="100%"|

-

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:

"Q139526 How to Send to the Serial Port by Using Mscomm32.ocx"

Purpose
The WriteComm function writes to the specified communications device.

Function Syntax
WriteComm(,, )   Argument       Description

     Specifies the device to receive the bytes. The OpenComm function returns this value.

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

     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.

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()   Argument       Description ---

     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"