Is there a way to store history for an integer tag and then reference one bit of the integer to create multiple pens on a easy chart?
The problem is easy chart takes in a tag path and creates the chart from that path. I don’t see how I could use getBit() or write some script to pass in the bits that I want.
There are times when the Easy Chart is not so easy. I don’t think there is a way to do what you’re looking for with the Easy Chart Component.
You could do this in the standard Chart component with some scripting.
Query the Tag History
Loop through the return data set
For each value of the tag convert to a Binary List
Create a Data set to hold the value of each bit at the given time stamp
Move the data set into the chart for display
That would look something like the following. Please note this has not been completely tested.
#defining a function to do the decimal to binary conversion
def dec2Bin(intValue,intNumBits=0,leftToRight=False):
intNumBits = abs(intNumBits)
seqBits = []
while intValue != 0:
seqBits.append(intValue % 2)
intValue = intValue/2
if len(seqBits) < intNumBits:
while len(seqBits) < intNumBits:
seqBits.append(0)
elif len(seqBits) > intNumBits and intNumBits != 0:
while len(seqBits) > intNumBits:
seqBits.pop()
if leftToRight:
seqBits.reverse()
return seqBits
#grab the tag history for the last 30 mins
endTime = system.date.now()
startTime = system.date.addMinutes(endTime, -30)
tagData = system.tag.queryTagHistory(paths=['integerTagPath'], startDate=startTime, endDate=endTime, returnSize=-1, aggregationMode="Maximum", returnFormat='Wide')
#the tagData data set will have the columns ['t_stamp', 'integerTagPath']
#we want to take the tag value at each t_stamp and expand it to the number
#of bits we're interested in
#for the sake of clarity I'm keeping the number of bits low
numBits = 4
headers = ['t_stamp','bit 0','bit 1','bit 2','bit 3']
chartData = []
for ts in range(tagData.rowCount):
newRow = [tagData.getValueAt(ts,'t_stamp')]
#get the bit values for the value from tag history
bits = dec2Bin(tagData.getValueAt(ts,'integerTagPath'),numBits)
for bit in bits:
newRow.append(bit)
chartData.append(newRow)
#now you have a data set relating the bit values
#to the time stamp from history
#just set the Chart Components Data property equal to
#this data set