CAPL3

12)  fileReadArray

Syntax            long fileReadArray(string section, string entry, string buffer, long bufferlen, string file);
Function         Searches for the variable entry in the section section of the file file. Its contents are interpreted as a list of byte values. The number format is decimal or with the prefix 0x it is hexadecimal. Numbers are separated by spaces, tabs, a comma, semi-colon or slash. The buffer is filled up to a quantity of bufferlen bytes.
Parameters     section = section of file
entry = name of variable
buffer = buffer for characters to be read
bufferlen = size of buffer in byte
file = name of data file
(backslashes should be doubled, i.e. “C:\\TEMP\\DATA.LOG”)
Returns          Number of characters read.
Note                This function is equivalent to the fileReadString() function. Since there is not a corresponding fileWriteArray() function, you can use fileWriteString() to write formatted strings to a data file that can later be read with fileReadArray() or fileReadString().
Example
Data in TEST.INI:
[DATA]
FIELD=1,2,3,0x20,100
CAPL Code:
...
int len;
char buf[20];
len = fileReadArray(“DATA”, “FIELD”, buf, elCount(buf), “TEST.INI”);
...
Result: len = 5. The array buf is filled with the values 1,2,3,32,100.
See also fileReadInt, fileReadFloat, fileReadString, fileWriteInt, fileWriteFloat, fileWriteString
Compatibility This function has restricted compatibility. Please see the function
compatibility chart for more details.

13)  fileReadFloat

Syntax             float fileReadFloat(string section, string entry, float def, string file);
Function         Searches for the variable entry in the section section of the file filename. If its value is a number, this number is returned as the functional result. If the file or entry is not found, or if entry does not contain a valid number, the default value def is returned as the functional result.
Parameters     section = section of file
entry = name of variable
buffer = buffer for characters to be read
bufferlen = size of buffer in byte
file = name of data file
(backslashes should be doubled, i.e.”C:\\TEMP\\DATA.LOG”)
Returns          The floating point number read if it is found in the data file, otherwise the value of the def parameter.
Example
Data in TEST.INI:
[DATA]
VOLUME=3.3000
CAPL Code:
...
float vol;
vol = fileReadFloat(“DATA”, “VOLUME”,0,“TEST.INI”);
...
Result: vol contains the value read or 0 if the data item was not found in the data file.
See also   fileReadArray, fileReadIntfileReadString, fileWriteInt, fileWriteFloatfileWriteString
Compatibility This function has restricted compatibility. Please see the function compatibility chart for more details.

14) fileReadInt

Syntax              long fileReadInt(string section, string entry, long def, string file);
Function         Searches for the variable entry in the section section of the file filename. If its value is a number, this number is returned as the functional result. If the file or entry is not found, or if entry does not contain a valid number, the default value def is returned as the functional result.
Parameters     section = section of file
entry = name of variable
def = value
file = name of data file
(backslashes should be doubled, i.e.”C:\\TEMP\\DATA.LOG”)
Returns          The integer read if it is found in the data file, otherwise the value of the def parameter.
Example
Data in TEST.INI:
[DATA]
ADDR=200
CAPL Code:
...
myAddress=fileReadInt(“DATA”,“ADDR”,0, “TEST.INI”);
...
Result: The value 2 is assigned to the variable myAddress. If the entry ADDR does not exist in the file TEST.INI the default value 0 is assigned to myAddress.
See also fileReadArray, fileReadFloat, fileReadString, fileWriteInt, fileWriteFloat, fileWriteString
Compatibility This function has restricted compatibility. Please see the function compatibility chart for more details.

15)  fileReadString

Syntax            long fileReadString(string section, string entry, string def, string buffer, long bufferlen, string filename);
Function         Searches for the variable entry in the section section of the file filename. Its content (value) is written to the buffer buffer. Its length must be passed correctly to bufferlen. If the file or entry is not found, the default value def is copied to buffer.
Parameters     section = section of file
entry = name of variable
def = value
buffer = buffer for characters to be read
bufferlen = size of buffer in byte
file = name of data file
(backslashes should be doubled, i.e.”C:\\TEMP\\DATA.LOG”)
Returns          Number of bytes read
Example
Data in TEST.INI:
[DATA]
NAME=Marty
CAPL Code:
...
int len;
char buf[20];
fileReadString(“DATA”, “NAME”, buf, elCount(buf), “TEST.INI”);
...
Result: buf is filled with the characters “Marty”.
See also fileReadArray, fileReadInt, fileReadFloat, fileWriteInt, fileWriteFloat, fileWriteString
Compatibility This function has restricted compatibility. Please see the function
compatibility chart for more details.

16)  fileWriteFloat

Syntax                  long fileWriteFloat(string section, string entry, float def, string file);
Function         Opens the file filename, finds the section and writes the variable entry with the                                      value. If entry already exists, the old value is overwritten. The functional result is 1 for                              success, or 0 for an error.
Parameters     section = section of file
                        entry = name of variable
                        def = value
                        file = name of file (backslashes should be doubled, i.e. “C:\\TEMP\\DATA.LOG”)
Returns          0 if an error has occurred else 1
Example
...
if(!fileWriteFloat(“DeviceData”, “DeviceAddr”, 2.2, “TEST.INI”))
write(“Error writing DeviceAddr to TEST.INI”);
...
This call writes the following entry in the file TEST.INI:
[DeviceData]
DeviceAddr=2.2
See also fileReadArray, fileReadInt, fileReadFloat, fileReadString, fileWriteInt, fileWriteString,

17)  fileWriteInt

Syntax             long fileWriteInt(string section, string entry, long def, string file);
Function         Opens the file filename, finds the section section and writes the variable entry with the value value. If entry already exists, the old value is overwritten. The functional result is 1 for success, or 0 for an error.
Parameters     section = section of file
entry = name of variable
def = value
file = name of file (backslashes should be doubled, i.e. “C:\\TEMP\\DATA.LOG”)
Returns          0 if an error has occurred else 1
Example
...
if(!fileWriteInt(“DeviceData”, “DeviceAddr”, 2, “TEST.INI”))
write(“Error writing DeviceAddr to TEST.INI”);
...
This call writes the following entry in the file TEST.INI:
[DeviceData]
DeviceAddr=2
See also  fileReadArray, fileReadInt, fileReadFloat, fileReadString, fileWriteFloat, fileWriteString

Compatibility This function has restricted compatibility. Please see the function compatibility chart for more details.

No comments:

Post a Comment