HOWTO: Using COM Port Communication with FoxProID: Q87808
|
FoxPro supports communicating through COM1 and COM2 using the following low-level file I/O functions:
FCHSIZE()
FCLOSE()
FGETS()
FOPEN()
FPUTS()
FREAD()
FWRITE()
NOTE: 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,1
For more information on the MODE command, see your MS-DOS user's guide.
COPY COM<x> CON
This command echoes the information sent to the port to the screen.
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:
COPY CON COMx
ATDT telephone_number_to_test
CTRL+Z
Additional query words:
Keywords : FoxDos
Version : 2.0 2.5 2.5a
Platform : MS-DOS
Issue type :
Last Reviewed: August 9, 1999