HOWTO: Using COM Port Communication with FoxProLast reviewed: May 27, 1997Article ID: Q87808 |
The information in this article applies to:
SUMMARYFoxPro supports communicating through COM1 and COM2 using the following low-level file I/O functions:
FCHSIZE() FCLOSE() FGETS() FOPEN() FPUTS() FREAD() FWRITE() MORE INFORMATIONNOTE: On some peer-to-peer networks, a path must be prepended to the file name for the COM port. Communications port I/O is supported only through the MS-DOS file I/O functions. This means that the communications parameters for the port must be specified at the MS-DOS level using the MODE command before FoxPro is run. The following MODE command demonstrates how to specify 9600 baud, no parity, 8 data bits, and 1 stop bit for the COM1 communications port:
MODE COM1: 9600,N,8,1For more information on the MODE command, see your MS-DOS user's guide. To test a communications port at the MS-DOS level, issue the following command at the MS-DOS prompt of the host computer. Substitute the port number for <x> in the command below:
COPY COM<x> CONThis command echoes the information sent to the port to the screen. If the screen does not show the correct information, communications at the MS-DOS level are not occurring correctly. Correct communications at the MS-DOS level are required before communications can occur in FoxPro. Once the communications parameters have been properly specified, the FoxPro low-level I/O functions provide access to the port. The code sample below reads a message terminated by a CTRL+Z character:
FIL = FOPEN("COM1",12) && Open COM1 port. IF (FIL < 0) ? "Error opening COM1" RETURN ENDIF done = .F. st = "" DO WHILE !DONE CH = FREAD(FIL,1) && Read one character from COM1 IF (CH != CHR(26)) && while not CTRL+Z. ST = ST + CH && Add character to string. ELSE DONE = .T. ENDIF ENDDO ? "Result string is: " ?? ST =FCLOSE(FIL) && Close port.To test whether communications are working properly, do the following:
NOTE: FoxPro does not provide a method to determine whether a character is waiting in the COM port buffer. |
Keywords : FoxDos
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |