Cicode Programming Reference > Cicode Function Categories > Trend Functions Introduction > TrnExportCSV

TrnExportCSV

Exports trend data to a file in CSV (Comma Separated Variable) format. The data is set at the specified Time and Period, and listed from earliest to latest. Any gated or invalid data is written as 0.0.

Data is stored as a grid, with each row time-stamped. The first column/field is the date, followed by the time, followed by the tags 1 to 8.

You can view the CSV file with a text editor, and import the file directly into other packages such as Excel for data analysis and presentation.

If you're using this function to export trends by using event numbers, you need to specify a valid event number in the Time argument, rather than a time.

Syntax

TrnExportCSV(Filename, Time, Period, Length, Mode, sTag1 ... sTag8, iDisplayMode1 ... iDisplayMode 8)

Filename:

The name of the destination path and file.

Time:

The starting time for the data being exported.

Period:

The period (in seconds) of the entries being exported. (This period can differ from the actual trend period.)

Length:

The length of the data table, that is, The number of rows of samples to be exported. for example if you put the length as 12, and you declare two tags to be exported, you get a grid with 12 rows of samples. Each row has values for each of the two tags making a total of 24 samples.

Mode:

The format mode to be used:

Periodic trends

1 - Export the Date and Time, followed by the tags.

2 - Export the Time only, followed by the tags.

4 - Ignore any invalid or gated values. (This mode is only supported for periodic trends.)

8 - The time returned will have millisecond accuracy.

Event trends

1 - Export the Time, Date and Event Number, followed by the tags.

2 - Export the Time and Event Number, followed by the tags.

8 - The time returned will have millisecond accuracy.

sTag1 ... sTag8:

The trend tag names for the data being exported.

iDisplayMode1 ... iDisplayMode8:

The Display Mode parameters allow you to enter a single integer to specify the display options for a trend (for a maximum of eight trends).

To calculate the integer that you should enter for a particular trend, select the options you wish to use from those listed below, adding their associated numbers together. The resulting integer is the DisplayMode parameter for that trend. By default, this argument is set to 3 (see the details for options 1 and 2 below).

Invalid/Gated trend options:

0 - Convert invalid/gated trend samples to zero.

1 - Leave invalid/gated trend samples as they are.

Invalid and gated samples that are not converted to zero will appear in the destination file as the string "na" (for invalid) or "gated".

Ordering trend sample options:

0 - Order returned trend samples from newest to oldest.

2 - Order returned trend samples from oldest to newest.

Condense method options:

0 - Set the condense method to use the mean of the samples.

4 - Set the condense method to use the minimum of the samples.

8 - Set the condense method to use the maximum of the samples.

12 - Set the condense method to use the newest of the samples.

Stretch method options:

0 - Set the stretch method to step.

128 - Set the stretch method to use a ratio.

256 - Set the stretch method to use raw samples.

Gap Fill Constant option:

n - the number of missed samples that the user wants to gap fill) x 4096.

Options listed in each group are mutually exclusive.

Return Value

0 (zero) if successful, otherwise an error is returned.

Related Functions

TrnExportDBF, TrnPrint

Example

TrnExportCSV("c:\TrnData.CSV", TimeCurrent(), 2, 60 * 60/2, 2,
"Feed", "Weight");

/* Export the last hour of data from the trend tags Feed and Weight.
The 60 * 60/2 is a decomposed way or writing 1800, which is the number of 2 second samples in 1 hour. */

See Also

Trend Functions