I have a gateway script triggers a tag that triggers an sql query to write some data to a table.
I'm getting two timestamps (very close to each other). How can i resolve this rather than changing plc code?
What does the script look like?
Are you filtering for the appropriate things? How are you determining if the query needs to be executed or not?
You'll be hard pressed to get any good help if we cant see the code is question.
This is the gateway tag:
Above is a PLC step number.
Below is the gateway script:
When fiinalData becomes 1, SQL query gets executed.
Ok, first you'll want to filter against initial change, otherwise you'll get a data entry at gateway startup.
This code can just be:
if not initialChange:
system.tag.writeBlocking([event.tagPath.parentPath.replace('PLCSteps','SQLGatewayTriggers/finalData'),[newValue.value == 100])
How is the query being triggered?
Ok. I'll try adding that.
Query is triggered using finalData tag.
Never seen a parameter used in a NQ like that before - this works? Personally I would put all control flow into the jython directly, I feel that is more clear. I would not like to see a NQ called in code that has the potential to be a complete no-op.
if serverTrigger == 1:
system.db.runNamedQuery("insertQuery",{'someParam':'somevalue'}
else:
# do fall back
And removing the IF :serverTrigger = 1
from the NQ - just have it be the INSERT statement.
I understand that, but how? Tag Change Script, Transaction Group ? There are a lot of ways to execute a query.
I call a NamedQuery in a table and give the path. It works well with IF :serverTrigger =1 except the multiple lines at very small time intervals (as i posted at the beginning).
I tried to call the query as @bkarabinchak.psi posted but it's missing the step number in the gateway script every time. Issue is still not resolved and any help is appreciated.
Does the tag serve any purpose other than triggering the query?
If not, I don't see why you wouldn't just call the named query in your gateway script.
It’s missing the number or you’re not sending it to the query??
Would need to see the complete query structure to help much more, but I would expect to see something similar to this.
Named Query:
INSERT INTO tableName
Values (:stepNumber)
Then in the script:
if not initialChange:
system.db.runNamedQuery('yourNamedQuery',{'stepNumber':newValue.value})
If your intention is to use the step number then I would just put the tag event on that tag.
As of right now I don’t see a need for the trigger tag, but I’m not sure what the query is truly trying to accomplish as you haven’t provided enough detail. Make the names generic if you need to obfuscate information for NDA reasons, we can work with that, but sprinkles of info and it’s still not working make it hard for us to help you.
Do don't have a parent project by any chance?
If the gateway script is in the parent project, then it will be inherited and the script will trigger once per inherited project and the parent. Same with report schedules.
I think @Faz is meaning that it's not triggering on the required step.
If we go back to the original script, and use the suggestions from others we would end up with:
step = newValue.value
if not initialChange and step == 100:
system.db.runNamedQuery("insertQuery",{'someParam':'somevalue'})
Then, the IF statement in the Named Query can be removed, as well as the redundant trigger tag.
@JordanCClark is correct. It's not triggering at the required step.
This is the query:
i want the above query to trigger when step is 100 and insert several tag values.
This is how data was written to my DB.
Could it possibly be tag scanclass issue?
Multiple trigger as i posted first is happening no matter how i trigger the query from ignition
Any idea why this is happening? I manually triggered the tag to run the query and it inserted two lines within milliseconds.
Did you define this event in an inheritable project? And have two leaf projects inheriting from it?
(Don't define events of any kind in an inheritable project.)
I have only one project so far and inheritable is set to false.
Is this a polling query binding? If it polls the query twice while the step is 100, it'll write twice (at least under the old logic where the query was happening unconditionally and just looking at the serverTrigger
parameter to see whether to update or not).
I notice that when you're running it from the change script:
it's writing every few seconds instead of milliseconds. In particular, I don't see the double writes happening in this screenshot.
As for the issue where some values aren't being written, that could be because the ignition tags aren't updating fast enough to keep up with the PLC. If those tags are reset to 0 and empty strings every machine cycle, Ignition might still be getting those old values. Usually if something depends on tight timing like this, I use system.opc.readValues()
instead of system.tag.writeBlocking
as it forces an OPC read and is going to be a fresh value