Applies To:
  • CitectSCADA 3.x, 4.x, 5.x, 6.x, 7.x 

Summary:
How do I create a report that logs to dBASE (DBF) files instead of text files, and what things are legal (cicode, math, multiple lines, etc)? 

Solution:
This type of report is set up similarly to normal reports. You need to define a report, a report format file, and a log device.

Configuration

In the Citect Project Editor, System menu, choose Reports and fill it out using the following example:

Name: DBFLog
Time: 00:00:00
Period: 00:00:10
Report Format File: DBFLog.TXT
Output Device: DBFLog

This tells Citect to run the report every 10sec, use DBFLog.TXT (in the project directory) to specify what to put in the report, and send the data to the System Device: DBFLog.

These values are only examples. However the format file should be a text file ending in .TXT. Click the help button on the report form for more information.

In the Citect Project Editor, System menu (Definitions menu in Citect version 3 and 4), choose Devices and fill it out using the following example:

Name: DBFLog
Format: {TimeDate,25}{Tag1,6}{Tag2,6}{Tag3,8}{Text,15}
File Name: [DATA]:DBFLog.DBF
Type: dBASE_DEV
No. Files: -1

* The Name has to be the same as the Output Device specified in the report.
* The Format specifies the field (column) names to create in the dBASE file, and the width of each. The names must be 10 characters long or less.
* The File Name is the file the data will be written to (C:\Citect\Data\DBFLog.DBF if you have Citect installed in the default directory).
* The Type must be dBASE_DEV to log to a DBF file.
* If you specify No. Files: -1 Citect will keep logging to the same file (DBFLog.DBF). To limit the file size, you can specify to create multiple files and set a Time and Period. Citect will keep logging to DBFLog.DBF until the period has elapsed, then it will rename it to DBFLog.001 and create a new DBFLog.DBF. Click on the help button on the device form for more details.

Open the report form again, and click the edit button. MS Wordpad (Windows Notepad in Citect version 3 and 4) will open. Type the following and close Wordpad. If you are asked what format to use, choose Text Document.

{Time(1) + " " + Date(9)}{Int1}{Int2}{Real1:##.###}{"Test Text"}

With this setup, the report will run every 10sec. Each time, it will add a row to the bottom of C:\Citect\Data\DBFLog.DBF. If you open the file in MS Excel, it will look something like this:

TimeDate

Tag1

Tag2

Tag3

Text

02:17:10 PM 10/05/1999 0 4 2.114 Test Text
02:17:20 PM 10/05/1999 1 2 3.452 Test Text
02:17:30 PM 10/05/1999 5 3 18.185 Test Text

Each value in {} will write to a different field (column) of the dBASE file.

* You can use cicode functions that will return values like Time(1)
* You can add strings together. For example: "Time:" + Time(1)
* You can use variable tags. In this example Int1, Int2, and Int3 are variable tags.
* You can use static text. For example: "Test Text"
* You can use format specifiers. For example: Real1:##.### will display 2 whole digits and 3 decimal places. See Formatting Numeric Variables in the online help.
* You can write several records (rows) at a time. For example:

{Time(1) + " " + Date(9)}{Int1}{Int2}{Real1:##.###}{"Machine 1"}
{Time(1) + " " + Date(9)}{Int3}{Int4}{Real2:##.###}{"Machine 2"}
{Time(1) + " " + Date(9)}{Int5}{Int6}{Real3:##.###}{"Machine 3"}

Cicode

You can't do math in the report fields (like {Int1 + Int2}), but you can write Cicode functions to do that. For example:

{CICODE}
INT iTotal;
iTotal = Int1 + Int2;
{END}
{Time(1) + " " + Date(9)}{Int1}{Int2}{iTotal}{"Test Text"}

This report format file will create a temporary variable called iTotal and write the sum of Int1 and Int2 to it. It will then write iTotal to the DBF file.

Cicode commands can be before or after the line of values that are being logged. For example, to log the sum of two values, and notify the operator that the report has run you could use:

{CICODE}
INT iTotal;
iTotal = Int1 + Int2;
{END}
{Time(1) + " " + Date(9)}{Int1}{Int2}{iTotal}{"Test Text"}
{CICODE}
Prompt("DBFLog Report Complete");
Sleep(2);
Prompt("");
{END}

Cicode commands can write to fields in the database using the Print() function. For example:

{CICODE}
Print(Time(1) + " " + Date(9));
Print(Int1);
Print(Int2);
Print("9");
Print("Test Text");
Prompt("DBFLog Report Complete");
Sleep(2);
Prompt("");
{END}

You can also break it up and use any combination of {} fields and Cicode Print commands to log the information.

Notes

* Be careful not to mix up {} and (). Curly braces {} must be around values to record and the keywords {CICODE} and {END}.
* Do not add blank lines to the report format file.
* Do not add spaces between or around the curly braces.
* Do a full compile after modifying the report format file. In the Citect Project Editor, Tools menu (File menu in Citect v3.xx), choose Options. Remove the checkmark from Incremental Compile. Click OK. Choose Pack from the File menu.
* Citect automatically creates the database and the columns (fields) in it using the names and widths specified in the device format if the file doesn't exist. If you change the format, delete the DBF file and Citect will create it with the new format.
* If you can't fit all the field names in the System Device Format field, lookup Include Files in the online help.
* dBASE_DEV devices use dBase III format which allows 128 fields. If more fields are needed, see Q5146.


Keywords:
 

Attachments