Main Content

readAtTime

Read data from an OPC HDA server at specified times

    Description

    DObj = readAtTime(HdaClient,ItmList,TimeStamps) reads data from the items defined by ItmList, from the OPC HDA Server associated with client object HdaClient, at the time stamps specified by TimeStamps.

    When no value exists for a specified timestamp, the server will interpolate a value from the surrounding values to represent the value at that timestamp, and the Quality for that timestamp will include the Interpolated bit.

    [ItmList,Value,Quality,TimeStamp] = readAtTime(HdaClient,ItmList,TimeStamps,DataType) returns the Value in the specified DataType along with the corresponding item ID, quality ID and timestamp.

    S = readAtTime(HdaClient,ItmList,TimeStamps,'struct') returns a structure containing the fields ItemID, Value, Quality and TimeStamp.

    example

    Examples

    collapse all

    Create an OPC HDA Client and connect the client to the server.

    hdaObj = opchda('localhost','Matrikon.OPC.Simulation');
    connect(hdaObj);

    Read the values of two items every 10 seconds for the last hour.

    DObj = readAtTime(hdaObj,{'Random.Real8','Random.Real4'},[datetime("now")-hours(1):seconds(10):datetime("now")]);

    Input Arguments

    collapse all

    OPC HDA client, specified as an OPC HDA client object.

    Example: opchda()

    HDA items, specified as a character vector, string, or supporting array of either.

    Example: {'Random.Real8','Random.Real4'}

    Data Types: char | string | cell

    Time boundaries, specified as datetime values returned by datetime function.

    Example: datetime(2018,11,28)

    Data Types: datetime

    Type of data in Value, specified as one of these:

    • 'single'

    • 'double'

    • 'int8'

    • 'int16'

    • 'int32'

    • 'int64'

    • 'uint8'

    • 'uint16'

    • 'uint32'

    • 'uint64'

    • 'logical'

    Output Arguments

    collapse all

    Raw OPC HDA data returned as an array of OPC HDA data objects, with one element per item. Each element of DObj is guaranteed to have the same timestamp as the other elements of DObj.

    HDA items, returned as a 1-by-N cell array of character vectors.

    HDA data, returned as an array of M-by-N values whose data type is specified by DataType.

    HDA quality, returned as an M-by-N array of quality IDs.

    Date and time of HDA data, returned from the server as an M-by-1 array of timestamps.

    Version History

    Introduced in R2015b