The VTSRead module is responsible for delivering the data it read from the I/O device. This is best accomplished by using the RefreshData module within the scope of the CallBackObj parameter of the VTSRead module.
The data type and structure for the three parameters, NewData, TimeStamp and Attribute can vary – read the following notes carefully.
RefreshData is provided for you as part of the VTSDriver module.
Format: CallBackObj\RefreshData(TimeStamp, NewData, Attribute, QueueObj, PropagateOnlyOnDataChange)
Parameters: TimeStamp Optional. If invalid, the system uses current time in UTC to timestamp the data.
Expressed in number of seconds since January 1st 1970 UTC, this value specifies the timestamp of the new data. This value must have the same structure as NewData. Each data point will be assigned its corresponding timestamp from the timestamp array.
Note: For event driven reads, you may wish to process only the data from a single address, rather than from a full read block. You can achieve this by setting all the TimeStamp array elements to invalid except for the one matching the element of NewData which you want to process.
NewData This is the value read from the I/O device. It may be either a single value, or an array of arrays having the same size as the MemAddress array used in the VTSRead function.
If an array of arrays, each element of the NewData array will contain another array which must be sized for the number of data points that are being returned for the matching MemAddress. This holds true even if there is only data value to return for each I/O address. Calling Refresh data with the NewData parameter specified as an array of arrays will work with all tags except the Analog Input.
Attribute Optional. Defaults to invalid. An array of attributes that gets assigned to the corresponding array of data.
If used, the size and arrangement of the array must be the same as NewData.
QueueObj This is used to either queue RPC data packets to client machines, or to only send the most recent data. This is only set within the VTSDriver, and should be set invalid when called from the communications (driver tag) driver.
PropagateOnlyOnDataChange Flag that when set true, will prevent data from being propagated through RPC unless the value has changed since the last time RefreshData was called.
NOTE: A single value must be passed to the Callback Object as an array of arrays. For example:
TimeValue = New(1); { declare as an array }
TimeValue[0] = … {set # of seconds since January 1st 1970 UTC }
TimeStamp = New(1); { declare as an array }
TimeStamp[0] = TimeValue { an array of arrays };
Invalid data is accompanied by a valid timestamp:
TimeStamp[i] = Some Valid Time;
Data[i] = Invalid;
Missing Data is indicated by an invalid timestamp:
TimeStamp[i] = Invalid;
Example 1:
Given MemAddress with two addresses, "Addr1" and "Addr2" and data for Addr1 = 1.23 and data for Addr2 = 2.34, you might do something like:
{ Make a data array }
Data = New(2);
{ Add first element }
Data[0] = New(1);
Data[0][0] = 1.23;
{ Add second element }
Data[1] = New(1);
Data[1][0] = 2.234;
{ Make it So }
CallBackObj\RefreshData( Invalid, Data, Invalid );
Example 2:
Multiple Data/Timestamp Value Pairs for each item in MemAddress, no Attributes
Given MemAddress with two addresses, "Addr1" and "Addr2"
and data/timestamps for
Addr1 = 1.23/2009-08-01 11:23, 1.24/2009-08-01 11:24
and data for Addr2 = 2.34/2009-08-01 11:21, 2.35/2009-08-01 11:22
you might
do something like:
{ Make a data array
}
Data = New(2);
TimeStamp =
New(2);
{ Add first element}
TimeStamp[0] =
New(2);
Data[0] =
New(2);
TimeStamp[0][0] = ConvertTimestamp(
\ODBCManager\ConvertToVTSTimeStamp(
"2009-08-01 11:23"),
"US Eastern Standard Time", 0,
"GMT Standard Time" );
Data[0][1] =
1.24;
TimeStamp[0][1] = ConvertTimestamp(
\ODBCManager\ConvertToVTSTimeStamp(
"2009-08-01 11:24"),
"US
Eastern Standard Time", 0,
"GMT Standard Time" );
{ Add second
element}
Data[1] = New(2);
TimeStamp[1] =
New(2);
Data[1][0] =
2.34;
TimeStamp[1][0] = ConvertTimestamp(
\ODBCManager\ConvertToVTSTimeStamp(
"2009-08-01 11:21"),
"US Eastern Standard Time", 0,
"GMT Standard Time" );
Data[1][1] =
2.35;
TimeStamp[1][1] = ConvertTimestamp(
\ODBCManager\ConvertToVTSTimeStamp(
"2009-08-01 11:22"),
"US Eastern Standard Time", 0,
"GMT Standard Time" );
{ Make it So }
CallBackObj\RefreshData( TimeStamp, Data, Invalid );