Edge Panel - Timer Event Script not running

Hi,

I need to monitor the seconds a boolean is on.

I created a simple script where I increment an int variable by 1 if a boolean is true. I tested in "script console" and saw it´s working.

When I set it in a "timer script" in "gateway events" to run every 1s "shared" or "dedicated" mode, nothing happens with the variable that should being incremented.

I'm using Edge Panel.

Hi,

Instead of doing this, how about using the system.tag.queryTagCalculations method ?

Use the "DurationOn" calculation.

For more info on available calculations:

Hi,

Thanks for very fast answer.

I've tried to use [system.tag.queryTagCalculations] but it didn´t work even in "script console". So I was wondering if it would work in Edge Panel version, maybe only in normal iginition, Do you know if it does?

Anyway, now I'm intrigued why the script that runs well in "script console" didn´t do it in "timer event - gateway". This is my first time trying to implement it, so I guess I'm doing something wrong. Do I need to enable something in the gateway web interface first?

The case is, I have a script that read and write to tags if I run it in script console. When I put it in a timer event it does nothing with the tags.

The problem was I was not saving the project but just hiting apply buttom.
After save I could see the error in the gateway script status and fix it.

Later i'll try the approach of using system.tag.queryTagCalculations for this task.

Alternatively, you can add a custom prop to the tag and use the tag's change script to write the timestamp to it when it turns on.

Thanks amarks, I'll try this also.

Just want to point out that the Script Console runs is Vison Client Scope, and so it sometimes has access to functions that aren't available in Gateway Scope, or vice versa. There are also functions which have different calling signatures depending on which scope you are calling them from.

It is possible to write a script which does what you want in the script console but is not capable of running in Gateway Scope.

The Script Console is just not a good place to test scripts intended for Gateway Scope unless you have take the necessary steps to insure that the script will be executed in the scope it is intended for, weather that be via Message Handler or Third Party Module.

1 Like

Hi Irose, thank you for the reply.

This is exactly the problem I'm having now again.

I'm using the function system.tag.queryTagHistory to calculate the totals produced by hour from a totalizer signal coming from a weight meter.

So it works perfectly in Scrip Console, but when I put it in Scheduled Gateway Event, the dataset returned comes with "null" in the value I need.

But if we look at the documentation of the function, it says it is gateway scope also.

You'll need to show your script, there may be something else that is bungling things up.

Sure, here it is:

def onScheduledEvent():

import datetime
data = datetime.datetime.now()
data_formatada = data.strftime("%d/%m/%Y %H:%M:%S")
Path_Hora_Atual = data.strftime("[edge]Plant/Y%Y/%m/%d/%H")	
endTime = system.date.now()
startTime = system.date.addMinutes(endTime, -60)	
dataSet = system.tag.queryTagHistory(paths=['WIT-001/Total_Global'], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="Range", returnFormat='Wide')
Total_Hora_Atual = dataSet.getValueAt(0,1)
system.tag.writeBlocking([Path_Hora_Atual], [Total_Hora_Atual])

onScheduledEvent()

So the value I need is supposed to be here, but it returns null
Total_Hora_Atual = dataSet.getValueAt(0,1)

As I said, if I put it in Console it works and I see the tag I need changing properly.
Another information is that the script runs normally, but returns null.

But you're script isn't doing that, it is calculating the the range for the last hour. Perhaps that's what you intend, perhaps not.

I agree, I do not see anything in the script that should not run the same way in Gateway Scope. I believe the only way you would get a null value is if there is only a single value in the time frame, but I am not entirely certain of that fact.

I have simplified the script to avoid the import (there is never a need to use the 'datetime' module, the system.date.* functions provide all the same functionality), and also to use only the necessary non-default parameters to the system.tag.queryTagHistory() function.

Path_Hora_Atual = system.date.format(system.date.now(),"'[edge]Plant/Y'yyyy/MM/dd/HH")
data = system.tag.queryTagHistory(['WIT-001/Total_Global'],returnSize = 1, aggregationMode = 'Range',rangeHours = 1)
Total_Hora_Atual = data.getValueAt(0,1)
system.tag.writeBlocking([Path_Hora_Atual],[Total_Hora_Atual])

Try that and see if it yields any different results (in theory it will be exactly the same).

I am interested in how and why you are generating tags by hour, that seems like something that is being done in a sub-optimal way IMO.

Irose, thanks for the code sugestion.

I updated the scheduled script with it, but result was the same as expected.

One intriguing thing I realized is that when I press "Apply" button in the gateway event scripts window, the script executes, and correctly. So, a few seconds after, running as per the schedule, it brings NULL value.

Well, about the "tags per hour" for now this was the way I found to store data, as I´m using Ignition Edge and it´s supposed not to have databases.

Can you log the value in the wrapper.log using the system.util.getLogger() function?

I'm not sure I understand this correctly. Do you mean that the tag value is NULL? Because your script obviously isn't returning anything, just writing to a tag at the end.

Using Louis's script, I've added the system.util.getLogger part.

Path_Hora_Atual = system.date.format(system.date.now(),"'[edge]Plant/Y'yyyy/MM/dd/HH")
data = system.tag.queryTagHistory(['WIT-001/Total_Global'],returnSize = 1, aggregationMode = 'Range',rangeHours = 1)
Total_Hora_Atual = data.getValueAt(0,1)
system.util.getLogger("ScheduledEventValue").info(Total_Hora_Atual)
system.tag.writeBlocking([Path_Hora_Atual],[Total_Hora_Atual])

Once this runs, check the "logs" section in the gateway and see whether the value is equal to null or not.

Hi,

I found the error, in a reply of our colegue @pturmel
I was just put the provider [edge] when calling the function

wrong way
data = system.tag.queryTagHistory(['WIT-001/Total_Global'],returnSize = 1, aggregationMode = 'Range',rangeHours = 1)

right way
data = system.tag.queryTagHistory(['[edge]WIT-001/Total_Global'],returnSize = 1, aggregationMode = 'Range',rangeHours = 1)

Thanks everyone.

1 Like