system.tag.queryTagHistory does not like strings

I am trying to retrieve a history entry for a string tag at a specific point in time. I have modified the sample script as follows:

import datetime startTime = datetime.datetime.now() - datetime.timedelta(minutes=10) endTime = datetime.datetime.now() dataSet = system.tag.queryTagHistory(paths=['[MSSQL]Line 2/LineConfig/MiddleRoll'], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="LastValue", returnFormat='Wide') print dataSet.getValueAt(0,1)

I store historical data at least every 10 minutes so if I set the endTime to the time I want and startTime to 10 minutes earlier I should capture at least one historical entry (I understand I am getting the most recent entry with this code but changing the date window is relatively easy). Then, if I set aggregationMode to LastValue I should get the piece of data I want.

However, it crashes because it tries to cast the string as a number:

Caused by: java.lang.ClassCastException: Error trying to coerce ' R1 - Rubber' to a number.

I have also seen this problem when developing reports and it seems to be caused by the same problem: The historian wants to turn the string into a number. How do I go about getting string data out of the historian?

CJVR, I think the returnSize and aggregationMode parameters only work with numbers, but I’m not positive. As a workaround you could use the following: import datetime startTime = datetime.datetime.now() - datetime.timedelta(minutes=10) endTime = datetime.datetime.now() dataSet = system.tag.queryTagHistory(paths=['[MSSQL]Line 2/LineConfig/MiddleRoll'], startDate=startTime, endDate=endTime, returnFormat='Wide') print dataSet.getValueAt(dataSet.rowCount - 1,1) This should get you the last value in the time range assuming you always capture at least one datapoint between startTime and endTime (otherwise you will be looking for an entry in the dataSet at row = -1).

Someone else feel free to chime in if I’m wrong about the returnSize and aggregationMode parameters.

-Will

That worked! Thanks.