in the process of using the test report, we may use to write our test results to the specified file. Compared with a test report, we may only care about some parameters. For example, in the results of stress testing, we may be more concerned about the results and key information of the final test case, but we don't really care about some of the information. At this time, we format the information we want to focus on into the text, which will also facilitate us to quickly get the results we want.
Function introductionfileClose
usage method
Function function
close the specified file. If an error occurs, the return value is 0, otherwise it is 1.
fileGetBinaryBlock
usage method
Function function
this function reads characters from the specified file in binary format. The source file must be opened in binary format. This function returns the number of characters read.
fileGetString
usage method
Function function
this function reads the string in the specified file into the buffer buff. Read characters until the end of the line is reached or the number of characters read is equal to buffsize -1. End of line marked as
1. Through a single line feed
2. Carriage return and line feed (DOS file)
the end of a line in the buffer is represented by a newline character. See also fileGetStringSZ. If the end of a line is encountered, the returned string contains a newline character. Otherwise, the next call to fileGetString will start reading on the last line, starting with the first character in the last call that is not suitable for the buffer. If an error occurs, the return value is 0, otherwise it is 1.
fileGetStringSZ
usage method
Function function
this function reads a string from the specified file. Read characters until the end of the line is reached or the number of characters read is equal to buffsize -1. End of line marked as
1. Through a single line feed
2. Carriage return and line feed (DOS file)
line breaks will not be included in the buffer. See also fileGetString. If an error occurs, the return value is 0, otherwise it is 1.
filePutString
usage method
Function function
writes the string to the specified file. If an error occurs, the return value is 0, otherwise it is 1.
fileRewind
usage method
Function function
this function resets the position pointer to the beginning of the file. If an error occurs, the return value is 0, otherwise it is 1.
fileWriteBinaryBlock
usage method
Function function
this function writes bytes of buffsize size in the specified file. The return value is the number of bytes written this time.
getOfflineFileName
usage method
Function function
returns the full path of a file of the currently used offline source file. If format 1 is used, the first file is returned; otherwise, the index of the returned file is passed as a parameter. There are three conditions for the return value:
0 - No error
1 - Buffer too small
2 - Other errors
Example
long isActive; char buffer[256]; long numFiles; long i; write("Offline source files:"); numFiles = getNumOfflineFiles(); for (i = 0; i < numFiles; ++i) { getOfflineFileName(i, buffer, 256); write("%s", buffer); }
getNumOfflineFiles
usage method
Function function
returns the number of configured offline source files. If an error occurs, the return value is - 1, otherwise it is the number of configured offline source files.
Example
long numFiles; numFiles = getNumOfflineFiles(); write("Number of configured offline source files: %d", numFiles);
getAbsFilePath
usage method
Function function
get the absolute path of the file. As a parameter, the currently configured relative path definition file should be used. When successful, this function returns the length of the full pathname, otherwise - 1. This function is not available in a distributed environment.
Example
on key 'x' { char absPath[256]; getAbsFilePath("Nodes\\Test.can", absPath, 256); write ("absPath: %s ", absPath); }
getProfileArray / getProfileFloat / getProfileInt / getProfileString
usage method
Function function
reads the value of the given variable from the specified part of the specified file.
getProfileArray -- search for variable entries in the file under the section section. Entries are interpreted as a list of values separated by commas, tabs, spaces, semicolons, or slashes. The 0x prefix represents a hexadecimal value.
getProfileFloat -- search for variable entries in the file filename under the section section. If its value is a number, this number is returned as the result of the function. If the file or entry is not found, or the entry does not contain a valid number, the default value def is returned as the result of the function.
getProfileInt -- search for variable entries in the file filename under the section section. If its value is a number, this number is returned as the result of the function. If the file or entry is not found, or the entry does not contain a valid number, the default value def is returned as the result of the function.
getProfileString -- search for variable entries in the file filename under the section section. Its contents (values) are written to the buffer buff. Its length must be passed correctly in buffsize. If the file or entry is not found, the default value def is copied to the buffer. If the read string length is greater than the buffer, the string is cut to the buffer length.
getUserFilePath
usage method
Function function
get the absolute path of the user file.
1. If it is executed in a distributed environment, if the user file is predefined, the absolute user file path (including file name) on the remote device (such as VN8900) is returned. If the file is not predefined, an error code is returned.
2. If it is a stand-alone environment, if the user file is predefined, return the registered absolute file path (including file name) of the user file. If the file is not predefined, the function returns the same result as getAbsFilePath (converting the path relative to the configuration directory to an absolute path).
Example
on preStart { char absPath[256]; VgetUserFilePath("MyCAPLDll.INI", absPath, 256); MyCAPLDllFunction(absPath); }
Open
usage method
Function function
this function opens a file named filename.
if access = 0, open the file for write access;
if access = 1, open the file for read access.
if mode = 0, the file is opened in text mode;
if mode = 1, the file opens in binary mode.
the file name must be passed to this function. The absolute file name is determined by the search process. First, a search is performed to determine whether the given file is located in the directory of the database. If the required file is not found, the active configuration directory is used.
openFileRead
usage method
Function function
this function opens a file named filename for read access.
if mode=0, the file is opened in text mode;
if mode=1, the file is opened in binary mode
openFileWrite
usage method
Function function
this function opens a file named filename for write access.
if mode=0, writing can be executed in text mode;
if mode=1, writing can be performed in binary mode. Existing files will be overwritten.
if mode=2, append data at the end of the file used for text mode.
if mode=3, append data at the end of the file in binary mode.
before calling this function, the write path must be set through the function SetWritePath. Otherwise, the configuration directory will be used. The relative file name must be passed to the function.
RegisterUserFile
usage method
Function function
dynamically register user files.
this function can be used
if the file names are unknown before running (for example, if they are read from an XML file, or if they contain counters as part of the file name)
avoid the continuous implementation of the file list in the Options dialog box of CANoe.
setFilePath
usage method
Function function
this function sets the read-write path of the directory. The path can be absolute or relative to the current active configuration.
Example
//set directory for reading setFilePath("C:\\Windows\\TEMP", 0); //set directory for writing setFilePath("D:\\TEMP", 1); //set directory for writing and reading setFilePath("C:\\TEMP", 2); on key 'i' { int defaultPara1; int returnParaInt; int counter; double defaultPara2; double returnParaFloat; char buffer [256]; //define symbolic values for read/write access mode dword FILE_PATH_R = 0; dword FILE_PATH_W = 1; dword FILE_PATH_RW = 2; defaultPara1 = -1; defaultPara2 = -1; //set absolute file path for writing setFilePath("C:\\TEMP" , FILE_PATH_W); // Write different values into the section "Parameter" of the INI file "Test.INI" // If no file path is specified, the path from previous setFilePath command is used writeProfileString ("Parameter","String","TestString","Test.INI"); writeProfileFloat ("Parameter","Float", 1.7845,"Test.INI"); writeProfileInt ("Parameter", "Integer", 8, "Test.INI"); // Read different values from the Section "Parameter" of the INI file "C:\\temp\\Test.INI" // And display the values in the Write Window //if an absolute path is to be used, this can be coded in the parameter <filename> directly returnParaInt = getProfileInt("Parameter","Integer",defaultPara1,"C:\\TEMP\\Test.INI"); returnParaFloat = getProFileFloat("Parameter","Float",defaultPara2,"C:\\TEMP\\Test.INI"); getProFileString("Parameter","String","Default String", buffer, elcount(buffer), "C:\\TEMP\\Test.INI"); write("Integer: %d", returnParaInt); write("Float: %f", returnParaFloat); write("String: %s", buffer); }
setWritePath
usage method
Function function
this function sets the write path for the functions openFileWritewriteProfileString, writeprofileint and writeprofilefloat. The path can be absolute or relative to the current active configuration. This feature is not available in a distributed environment. After the drive letter and between folders, you must enter two "\", such as setWritePath("E:\testconfiguration\exercise").
Example
SetWritePath("C:\\TEMP")– after the drive letter (e.g. "C:") you have to enter two backslashes "\\!
writeProfileFloat
usage method
Function function
open the file name