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'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.
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.
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.
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.