version 6.0
Compatibility Note: This command is now obsolete; it is kept only for compatibility reasons and will be removed in future versions of the plug-in. It is strongly recommended to use the 4D commands of the "Communications" theme.
AP fopen (file | port; mode) Long integer
Parameter | Type | Description | |
file | port | String | Name of the file or port to be opened | |
mode | Integer | Opening mode | |
0 = write only | |||
1 = read only | |||
Function result | Long integer | Value to be used with AP FPRINT, or | |
0 if the file or port cannot be open |
Description
The AP fopen command calls the "fopen" ANSI C command, which enables the opening of serial or parallel ports (on Windows) or the direct creation of files.
The value returned by this function is then used with the AP FPRINT command to write through the port, or to write the file. The opened port or file can then be closed using the command AP FCLOSE.
Note: On Mac OS, this function works only with the direct creation of files.
Examples
1. Writing "hello world" on the parallel port:
port:=AP fopen ( "LPT1";0 ) AP FPRINT ( port; "hello world" ) AP FCLOSE ( port )
2. Writing "hello world" on the serial port:
port:=AP fopen ( "COM1";0 ) AP FPRINT ( port; "hello world" ) AP FCLOSE ( port )
3. Writing "hello world" in a file:
port:=AP fopen ( "C:\myfile.txt";0 ) AP FPRINT ( port; "hello world" ) AP FCLOSE ( port )
4. Reading a file:
port:=AP fopen ( "C:\myfile.txt";1 ) MyVar:=AP fread ( port ) AP FCLOSE ( port )
See Also