I am not quite sure I understand what you’re trying to do, but let’s address a few things about your script:
def counter(time):
date = system.date.now()
agg = 0
changeVal = system.tag.readBlocking(["[Sample_Tags]Bool_array[0]"])
now = system.date.getHour24(date)
while now == time:
if changeVal == True:
agg += 1
print agg
count(15)
Here are the 2 possible outcomes (assuming the datetime logic is sound):
- it’s 15:** :
now == time
returns true, the loop is entered. Since this condition stays true, it’s an infinite loop.
- it’s not 15:**:
now == time
returns false, the loop is not entered, agg
's inital value (0) is printed.
I think you had something like this in mind:
def counter(time):
change_val = system.tag.readBlocking(["[Sample_Tags]Bool_array[0]"])
agg = 0
while system.date.getHour24(system.date.now()) == time:
if change_val:
agg += 1
print agg
counter(15)
Here, the date is evaluated at each iteration of the loop, which gives it a chance to exit.
But, it is going to loop continuously until it’s 16:00. Is that what you actually want ?
Even if that’s the case, you may want to set up some delay between each iteration, with sleep()
for example.
Note that you shouldn’t test for truth with == True
in python.
Also, if you’re expecting to get different values for change_val
, there’s another mistake, as it won’t be reevaluated at each iteration. You’d need to put that tag read in the loop. You also need to “unpack” the results of the readBlocking
call, as it return a list of qualified values: readBlocking([path])[0].getValue()
def counter(time):
agg = 0
while system.date.getHour24(system.date.now()) == time:
if system.tag.readBlocking(["[Sample_Tags]Bool_array[0]"][0].getValue()):
agg += 1
print agg
counter(15)
That’s an astronomical number of tag reads !
Now, this will only execute when the function is called. If you wanted to make sure it executes from 15:00 to 15:59:59, you’d need to actually run that loop continuously, all day long.
There are a lot of ways to do things in ignition, some better than others. I don’t think this would be the best way of doing what you want to do, even without knowing what it is you want. Not even a good way, most likely one of the worst.
If you could be a little bit more explicit about your issue, I’m sure folks around here will help put you on the right track.