Hi! I want to be able to change a bunch of tags values using a button. Doesn't matter the number, just need the values to change to activate a bunch of tag event scripts. What would be the best way to do this? Can I use some kind of random int function? Is there something else that would work better? Any help would be appreciated, thanks!
- Are these value change scripts, or Gateway Tag Change scripts?
- Is each script specific to that particular tag?
The fact that you are asking this question makes me think that the scripts don't actually belong in a Tag Change event of any kind, but rather should be in the Library (there is an argument that they should be there anyway) so that you can just call the scripts natively.
Use a script and https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-writeBlocking to write out the current millisecond value from system.date.now | Ignition User Manual. Use modulo division to return the last three digits (or whatever you want).
x = system.date.now() % 1000
should do the trick.
This, with the caveat that if calling from Vision, you may need to use a message handler to run in gateway scope. (Or use my @system.util.runInGateway
decorator.)
Value change scripts, the scripts are unique to each tag. Using "Trigger tags" to activate the value change tag event scripts. Where is this library where you think I should place these scripts in? Also, is there a way I can set the rate at which these scripts run then? Like once every hour?
So, expensive scripts? Such should never be tag valueChange
event scripts anyways. Use gateway events of whatever type is most appropriate. (Probably a scheduled event.) (Put the bulk of the code in a project library script function.)
Both of these are under the "Scripting" section of the designer navigation tree.
Should I use Client or Gateway Event Timer Scripts you think?
Like they use the current value of that tag, or each tag runs a specific script? Sorry, just trying to grasp what is happening.
Does it need to happen only when a client is running? Does it need to happen for each client that is running?
Generally, I would probably use a Gateway Event. Also note that Timer scripts are not guaranteed to happen at a set interval (e.g. at the top of every hour).
Each tag runs a specfic script. So I think it would make more sense to put them all in as Gateway Event Timer Scripts. Needs to run in the specific client, not for each client, so maybe client event scripts make more sense. Sorry, I was taught to use the tag event scripting when I first was learning ignition. Didn't even know these things existed.
What does this mean? Are you using client tags? Why are they specific to a client?
Tag Value Change scripts have their place for sure, but there are restrictions to what you can do there. For instance, they run in a fixed thread pool (three IIRC), and if you exceed that you can miss events. Best practice says that they should execute in single digit milliseconds, and you should basically never touch a database.
Its specific to a project im in. I put one of my tag event scripts on the gateway events timer. Hasn't ran once yet and havent gotten anything on timer or wrapper log file... What's going on?
Found an error in the script console. No idea what the second half means. Script should be fine. Just ran it by changing the value on the original tag event script. Need help.
>>> ImportError: Cannot import site module and its dependencies: Error loading module LOCAP_PD_Trigger: AttributeError: 'NoneType' object has no attribute 'strip'
Determine if the following attributes are correct:
* sys.path: [C:\Users\mmm\.ignition\cache\gwlocalhost_8088\C0\pylib, C:\Users\**\.ignition\cache\resources\platform\jython-ia-2.7.2.1.jar\00000000A5AE7F4C\Lib, __classpath__, __pyclasspath__/]
This attribute might be including the wrong directories, such as from CPython
* sys.prefix: C:\Users\NOTGIVINGAWAY\.ignition\cache\resources\platform\jython-ia-2.7.2.1.jar\00000000A5AE7F4C
This attribute is set by the system property python.home, although it can
be often automatically determined by the location of the Jython jar file
You can use the -S option or python.import.site=false to not import the site module
Okay, so a little explanation.
Client Event Scripts are specific to vision, and are project resource, but they are run independently for each running client. They are useful for things that you want to occur for every running client, but the result may be different based on the context provided by that client.
Gateway Event Scripts are also project resources, however, they are not specific to any module and will run regardless of if there is a client running or not. Once you have created one, a project must be saved before that script will begin execution.
Timer scripts execute periodically at a fixed delay or rate. If set for a fixed delay then it will wait for that delay between each execution. So if you have a fixed delay of 1 sec and your script takes 5 secs to run, then your script will execute once every 6 seconds. If they are set for Fixed rate then they attempt to run at a fixed rate relative to the first execution, which means when it starts matters, so the time the script occurs will be influenced by things like Gateway restarts, background processes and other things.
If you need the script to occur at a specific time, then a scheduled event is a better fit.
I would say that these scripts should absolutely be in the script library and be called from a Gateway Event.
Scripts run in tags value changed events run in Gateway Scope, scripts run in the Script Console run in Vision Client Scope. This means that things which exist for the script in one place may not be present in the other. The Script Console should not be used for testing scripts that will run in a Gateway scope.
I would need to see the script to be certain, but it looks like it is trying to import a python library that is available on the gateway server, but isn't available on the machine you are running the script console on.
Thanks!