File functions#

FileVariableF#

FileVariableF(Mode:=0, Index:=1, Value:=0.0)#

User may save up to 2048 REAL values into table which is saved to disk max 1 minute after changing value.

Note

At power break it is possible to lose changes made during last minute.

Parameters:
  • Mode (INT) –

    • 0 - Read values

    • 1 - Write values

  • Index (INT) – Index 1..2048 of file variable

  • Value (REAL) – Value to be saved. Not used if Mode=0.

Example:

Read value of file variable 7 to IEC variable x. Add 1 to it and save it again.

VAR
    x : REAL;
END_VAR

x := FileVariableF(Mode:=0, Index:=7, Value:=0.0);
x := x + 1.0 ;
x := FileVariableF(Mode:=1, Index:=7, Value:=x);

WriteFileF#

WriteFileF(FileName:='Report.txt', OpenMode:=155, Real1:=0.0, Real2:=0.0, Str1:='', Str2:='', Format:='LF#TIME# **** Start of report ****LF')#

Writes files to RAM disk and where they are copied to www folder with 5 minute interval. It is possible to lose latest changes at power break. When files are requested by browser then server sends always latest file regardless of location of latest file.

Parameters:
  • FileName (STRING) – Name of report file. Folder is /hdisk/fidelix/www.

  • OpenMode (INT) –

    • 1..9 - Write to end of indexed file. Max file size is 30kB.

    • +50 - Copy will be saved before clearing main file.

    • +100 - File will be cleared before opened.

    Example:

    153 - Write indexed file 3. Clear file at first but make a copy.

  • Real1 (REAL) – Real parameter

  • Real2 (REAL) – Real parameter

  • Str1 (STRING) – String parameter

  • Str2 (STRING) – String parameter

  • Format (STRING) –

    Format text may contain static text, variable values and linefeeds. Linefeeds are added to text by embedding letters LF Variable values are added to text by embedding output modifier text between two # letters.

    Examples of possible output modifiers

    #TIME#

    Date and time.

    #I#

    REAL - Without decimals (I=integer).

    #4I#

    REAL - Without decimals, 8 char wide field, number at left.

    #-8I#

    REAL - With two decimals, 6 char wide field, number at right.

    #6.2R#

    REAL - With two decimals, 6 char wide field, number at right.

    #-20S#

    STRING - 20 char wide field, text at left.

Example:
PROGRAM WriteFile

VAR
    i : INT;
    PointID1 : STRING(30);
    PointID2 : STRING(30);
    ai1, ai2 : REAL;
END_VAR

(* This program creates files Report0.txt .. Report5.txt
 *
 * If execution interval is 60000ms we will have reports with one minute intervals.
 * Reports may be displayed in graphics by creating text objects with links
 * /Report0.txt, /Report1.txt etc.
 *)

PointID1 := 'SENSORTEST_FARNELL';
PointID2 := 'SENSORTEST_PRODUAL';

(* Read values for two points *)
ai1 := GetAnalogPointF(Name:=PointID1);
ai2 := GetAnalogPointF(Name:=PointID2);

(* Open new file Report0.txt
 *
 * Old reports are saved with names Report1.txt .. Report5.txt
 * Print date, time and header into start o file
 *)
i := WriteFileF(
    FileName:='Report.txt',
    OpenMode:=155,
    Real1:=0.0,
    Real2:=0.0,
    Str1:='',
    Str2:='',
    Format:='LF#TIME# **** Start of report ****LF'
);

(* Adding first point name and value to file Report0.txt *)
i := WriteFileF(
    FileName:='Report.txt',
    OpenMode:=55,
    Real1:=ai1,
    Real2:=0.0,
    Str1:=PointID1,
    Str2:='',
    Format:='Point1 #-30S# #6.2R# C LF'
);

(* Adding second point name and value to file Report0.txt *)
i := WriteFileF(
    FileName:='Report.txt',
    OpenMode:=55,
    Real1:=ai2,
    Real2:=0.0,
    Str1:=PointID2,
    Str2:='',
    Format:='Point2 #-30S# #6.2R# C LF'
);

(* Adding date, time and header to file Report0.txt *)
i := WriteFileF(
    FileName:='Report.txt',
    OpenMode:=55,
    Real1:=0.0,
    Real2:=0.0,
    Str1:='',
    Str2:='',
    Format:='#TIME# **** End of report ****LFLF'
);

END_PROGRAM