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 timestamps 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. You can specify only one OPC HDA client, and the client must be connected to the server.

    Example: hdaClient = opchda(_)

    IDs of HDA items IDs, 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 OPC HDA data object or an array of OPC HDA data objects. Each item in the itemList corresponds to a data object in the array. All elements in the dObj have the same timestamp.

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

    HDA data, returned as a M-by-N array, where each element is of the same data type as specified in DataType.

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

    Timestamp of data read from server, returned as an M-by-1 vector of timestamps.

    Version History

    Introduced in R2015b