Scheduled Script not working sometimes

I have a very simple scheduled gateway script to flip a bit that resets some transaction group hour meters.
When I manually flip the bit, the hour meters successfully reset.
When I set the scheduled script to the current time + 2 min and save, It runs successfully, flips the bit, and resets the hour meters.
When I set the scheduled script to the time I need it to reset (after the shift), seemingly nothing happens. When I check the runtime values (that should be reset by the bit going high) the following morning, they are not reset.

*This script should run twice, after hours. Once to set the bit high (to reset tx groups), once again to reset the reset bit.

Please help.
see scheduled gateway script below:

def onScheduledEvent():
   resetBit = system.tag.readBlocking("[default]NJSec_Runtime_Reset_All")[0].value

   if resetBit == True:
	   system.tag.writeBlocking("[default]NJSec_Runtime_Reset_All.value", False)
	
   else: 
  	   system.tag.writeBlocking("[default]NJSec_Runtime_Reset_All.value", True)

I don't think you want or need the .value in the tag path. Just [default]NJSec_Runtime_Reset_All.

You should throw a logger in there somewhere to verify. Maybe it's just not the value you're expecting it to be? Before changing anything I Would modify this to be like

def onScheduledEvent():
   logger = system.util.getLogger("Reset logger")
   resetBit = system.tag.readBlocking("[default]NJSec_Runtime_Reset_All")[0].value
   logger.info("Reset bit value %s type %s"%(str(resetBit),str(type(resetBit))))
   if resetBit == True:
       logger.info("In true block")
	   system.tag.writeBlocking("[default]NJSec_Runtime_Reset_All.value", False)
	
   else: 
       logger.info("In else block")
  	   system.tag.writeBlocking("[default]NJSec_Runtime_Reset_All.value", True)

Just to verify what exactly is going on before making any changes.

You may also want to examine the results of your writeBlocking - you get a code back per right but it does not throw an error so it wouldn't pop up in your logs.
results = system.tag.writeBlocking("[default]NJSec_Runtime_Reset_All.value", False) will give you a list of result codes - maybe its just having an issue writing?

1 Like

You don't need .value on the write blocking

Write Blocking can just write to the tag path. This is probably erroring when run so it doesn't work. I would try running the script in the script console, you should get any exceptions appear in there.

1 Like

You won't get an exception for bad tag writes. You will get a list back of QualityCode objects that say if the write was successful or bad or what have you.

I do suspect the .value is what is throwing it though. I am guessing he is getting a Bad_NotFound quality code back or something like that.

1 Like

ah yeah that's true, could through a print(system.tag.writeBlocking.....) and read off that result in the script console if that is possible.
system.tag.write() if I remember does through an exception, but that is depreciated now.

1 Like

Thank you both for your input. I tried the script you provided but yielded similar results. See logs attached. Please advise.

It looks like it ran successfully but my hour meters were not reset when I checked this morning.

You're going to have to give us more context on these hour meters. Are they an ignition or opc tag? Where is the logic to reset them located? etc. All we know / can see is your scheduled event about the reset bit which does seem to be working as intended now.

1 Like

The logic to reset them is in the transaction group settings. They are ignition memory tags. When I manually trigger the bit, the values reset as they should. See ss of tag config & tx group settings below:


Nah, the value is a property and can be specified to be written to or read just like any other tag property.

@MC2338 You should be providing system.tag.writeblocking() with a list of values to write.

def onScheduledEvent():
   logger = system.util.getLogger("Reset logger")
   resetBit = system.tag.readBlocking("[default]NJSec_Runtime_Reset_All")[0].value
   logger.info("Reset bit value %s type %s"%(str(resetBit),str(type(resetBit))))
   if resetBit == True:
       logger.info("In true block")
	   system.tag.writeBlocking(["[default]NJSec_Runtime_Reset_All.value"], [False])
	
   else: 
       logger.info("In else block")
  	   system.tag.writeBlocking(["[default]NJSec_Runtime_Reset_All.value"], [True])

I modified @bkarabinchak.psi 's script to have the correct syntax for writeBlocking() yes I'm aware that it will work with single elements, but the preferred method is to use lists. The script should technically work but it's just one thing to get out of the way. I would get in the habit of always using lists.

1 Like

If you only do a single element you don't need to put it in a list for writeBlocking anymore on the newer versions of 8.1.X as I recall. But perhaps that is the issue here.

@MC2338 Did you ever examine the result code of the write?

1 Like

yep, I know.

2 Likes

Ha I should read your whole post before replying :upside_down_face:

Everything else seems fine though. Going to need to see what the result code of the write is but if NJSec_Runtime_Reset_All is just a memory tag I don't know why it would be failing.

1 Like

I would probably write this script like:

def onScheduledEvent():
    resetBit = system.tag.readBlocking(['[default]NJSec_Runtime_Reset_All'])[0].value
    system.tag.writeBlocking(['[default]NJSec_Runtime_Reset_All'],[not resetBit])
2 Likes

I'm on the tail end of this thread, and I don't know the implementation details of the hour meter, but it would be better to handle it in a rollover, odometer style and just subtract current value from last record.

4 Likes

This, for sure.

But I suspect the OP's problem is not holding the reset bit on long enough for the transaction group to execute to see it.

1 Like

We would prefer to have it reset everyday. I think we got it figured out though.

The theory is: the time that the script in question was scheduled to run was a time that the machines (where running bool bit is read from) were offline. Because the machines were offline the transaction groups would not reset. We adjusted the time of execution to a time when we knew all machines should be online. This did lead us to another issue which I will describe in another thread. BUT, since this change we have seen all tx groups reset everyday (minus machines that are still offline).

*This is after reviewing the issue with IA Tech support who confirmed this is the issue

1 Like