Hello:
I have 100 tags, tag1-tag100, how can I assign them in batches (tag event scripts/value changed)
like this :
for i in range(1,101):
system.tag.writeBlocking(["tagi"],10)
i = i +1
#Then the value of tag1-tag100 will be equal to 10
Hello:
I have 100 tags, tag1-tag100, how can I assign them in batches (tag event scripts/value changed)
like this :
for i in range(1,101):
system.tag.writeBlocking(["tagi"],10)
i = i +1
#Then the value of tag1-tag100 will be equal to 10
Welcome!
for i in range(1,101):
system.tag.writeBlocking(["tag"+str(i)],10)
i = i +1
There is no need for the i = i + 1
The i will automatically be incremented by the for loop
.
...but if there were a need for something like i = i + 1
, it would probably be more pythony to write it:
i += 1
If you actually want to write all 100 tags to 10 though, you should not write them one by one as this is incredibly inefficient and slow. Write them all at once with:
ints = range(1, 101)
system.tag.writeBlocking(["tag{}".format(i) for i in ints] , [10]*len(ints))
Hello,Thank you for your reply,This assignment function is working,I want this 100 tags to add 10 per hour,like this:
for i in range(1,101):
Vi= system.tag.readBlocking(["tag" + str(i)])[0].value
Vi =Vi +10
system.tag.writeBlocking(["tag" + str(i)],Vi)
What should i do?
I question the utility overall of 100 tags updating in lockstep, but...
count = 100
paths = ["tag{}".format(i + 1) for i in xrange(count)]
currentValues = [qv.value for qv in system.tag.readBlocking(paths)]
newValues = [currentValue + 10 for currentValue in currentValues]
system.tag.writeBlocking(paths, newValues)
Thank you for your reply,it's work.
The reason why I need 100 tags here is that I have 100 data to save to the database. I do it through tag history, which may be a bit stupid. Do you have any simple method?
Create a dedicated SQL table and write your values into that. It'll be far easier to query from that way as well