主要内容

read

Read data from PI Data Archive

Since R2022a

Description

piValues = read(piClient,tagName) reads the latest data value from each of the specified tags of the AVEVA® PI Data Archive that the PI client piClient is connected to. tagName can be a string or vector of strings. The data is returned to piValues as a timetable.

piValues = read(piClient,tagName,Earliest=true) reads the earliest value from each of the specified tags.

piValues = read(piClient,tagName,DateRange=[startDate,endDate]) reads data points in the range between the start and end dates, specified by the datetime values of [startDate,endDate].

piValues = read(piClient,tagName,DateRange=[startDate,endDate],Interval=timeStep) reads the data points in the given time range interpolated for each interval specified by the duration timeStep.

Note

You must install the AF SDK library to use this function. For more information, see AF SDK Overview.

example

Examples

collapse all

Read the latest data point of a single tag.

piValues = read(piClient, "Plant1_generator1_voltage");

Read the earliest data point of a single tag.

piValues = read(piClient, "Plant1_generator1_voltage", Earliest=true);

Read data points of a single tag over the past one-day period.

startDate = datetime("now") - days(1);
endDate = datetime("now");
piValues = read(piClient, "Plant1_generator1_voltage", DateRange=[startDate,endDate])
piValues=

  5×3 timetable

              Time                        Tag                  Value    Status
    ________________________    ___________________________    _____    ______

    15-Feb-2024 05:34:53 UTC    "Plant1_generator1_voltage"     0.88     Good 
    15-Feb-2024 09:34:53 UTC    "Plant1_generator1_voltage"    0.912     Good 
    15-Feb-2024 11:34:53 UTC    "Plant1_generator1_voltage"     0.86     Good 
    15-Feb-2024 15:08:29 UTC    "Plant1_generator1_voltage"     0.89     Good 
    15-Feb-2024 19:34:53 UTC    "Plant1_generator1_voltage"     0.87     Good 

Read all data points of multiple tags over a 6-hour period, interpolating every 5 minutes.

startDate = datetime(2021,6,12,14,10,30); % 12-Jun-2021 14:10:30
endDate = startDate + hours(6);
piValues = read(piClient,["Plant1_generator1_voltage","Plant1_generator1_current"], ...
           DateRange=[startDate,endDate], Interval=minutes(5));

Input Arguments

collapse all

Client connected to AVEVA PI Data Archive, specified as an icomm.pi.Client object. You create the object with the piclient function.

Example: piClient = piclient(_)

Data Types: object

Tag names to read from, specified as a string, string array, character vector, or cell array of character vectors. You can also specify tags with a table, in the format returned by the tags function.

Example: "Power_ckt2"

Data Types: char | string | table | cell

Date range of data to read, specified as a two-element vector of datetime values returned by the datetime function. You can also specify a time zone in the datetime values. By default, the function uses the time zone of the local system.

Example: [datetime("1-Jan-2020"),datetime("31-Jan-2020")]

Example: [datetime("today",TimeZone="America/New_York"),datetime("now",TimeZone="America/New_York")]

Data Types: datetime

Interval span for data interpolation, specified as a duration value.

Example: hours(1)

Data Types: duration

Output Arguments

collapse all

Data point values read from the PI Data Archive, returned as a timetable. The timetable includes data values for the specified date range in UTC time.

Version History

Introduced in R2022a

See Also

Functions