Hello,
I’m trying to develop a module that queries tag history data from the last 20 minutes. I’m not sure if im setting up the BasicTagHistoryQueryParams right or if I’m storing data in the DataStream correctly because I keep getting this error in the logs:
E ResultWriter 28Oct2020 11:39:12 Error executing historical tag read.
This is the code that I’m working with. Note that as it is right now, the StreamingDataset is not storing any data.
private float queryHistorian(ArrayList<TagPath> tagPaths) {
StreamingDataset dataStream = new StreamingDataset();
try {
BasicTagHistoryQueryParams params = new BasicTagHistoryQueryParams(tagPaths, minutesAgo(21), minutesAgo(1), -1, null, ReturnFormat.Tall, null, null);
GatewayContext gatewayContext = GatewayHook.getGatewayContext();
dataStream.initialize(columnNames, columnTypes, false, -1);
gatewayContext.getTagHistoryManager().queryHistory(params, dataStream);
dataStream.readFully();
return function(dataStream); //returns the value that I need using the DataSet from the last minutes
} catch (Exception e) {
logger.info(e.getClass() + " " + e.getMessage());
} finally {
dataStream.finish();
return function(dataStream);
}
}
Column names and column types are the ones found on sqlt_data_x_x_x here: https://docs.inductiveautomation.com/display/SE/Tag+History+Tables+Reference
If I could get any input on what’s wrong with the code or an example of a better way to query the tag historian it would be very appreciated.
Thanks in advance!