Main Content


Read data from an OPC HDA server at specified times


DObj = readAtTime(HdaClient,ItmList,TimeStamps)
[ItmList,Value,Quality,TimeStamp] = readAtTime(HdaClient,ItmList,TimeStamps,'DataType')
S = readAtTime(HdaClient,ItmList,TimeStamps,'struct')


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. HdaClient must be a scalar connected OPC HDA Client. ItmList is a character vector, string, or array defining one or more Fully Qualified ItemIDs in the name space of the OPC Server. TimeStamps must be a vector of MATLAB date numbers. DObj is returned as an opc.hda.Data object array the same size as the number of items specified by ItmList. Each element of DObj is guaranteed to have the same time stamp as the other elements of DObj.

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

[ItmList,Value,Quality,TimeStamp] = readAtTime(HdaClient,ItmList,TimeStamps,'DataType') where 'DataType' is one of the built-in MATLAB numeric arrays ('double', 'single', etc.) or 'cell', returns the data in the specified data type. ItmID is returned as a 1-by-N cell array of character vectors. Value is an array of M-by-N values. Quality is an array of M-by-N quality IDs, and TimeStamp is a M-by-1 array of time stamps as MATLAB date numbers.

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


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

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

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

DObj = readAtTime(hdaObj,{'Random.Real8','Random.Real4'},[now-1/24:10/86400:now]);

Version History

Introduced in R2015b

See Also