Microsoft KB Archive/87808

{|
 * width="100%"|

-

The information in this article applies to:


 * Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a

-

SUMMARY
FoxPro supports communicating through COM1 and COM2 using the following low-level file I/O functions:

  FCHSIZE FCLOSE FGETS FOPEN FPUTS FREAD FWRITE

MORE INFORMATION
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.

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  in the command below:   COPY COM CON This 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(&quot;COM1&quot;,12)       && Open COM1 port. IF (FIL < 0) ? &quot;Error opening COM1&quot; RETURN ENDIF done = .F.  st = &quot;&quot; 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

? &quot;Result string is: &quot; ?? ST

=FCLOSE(FIL)               && Close port. To test whether communications are working properly, do the following:

 Find a telephone number to test. Add a &quot;9&quot; if necessary to get an outside line. To add a pause after the 9, add a comma (&quot;,&quot;). If the number is long distance, add a &quot;1&quot;. For example, you could use 9,12065551212 (the number for information).  Type the following commands at the MS-DOS prompt, where  is the port number, and press ENTER at the end of each line:       COPY CON COMx ATDT telephone_number_to_test CTRL+Z 

If the communication is successful, you will receive the message &quot;1 file copied&quot; and then be returned to an MS-DOS prompt. Then, you will hear the modem dialing.

NOTE: FoxPro does not provide a method to determine whether a character is waiting in the COM port buffer. Additional query words:

Keywords         : FoxDos Version          : 2.0 2.5 2.5a Platform         : MS-DOS Issue type       :
 * }