I have connected to my plc and have successfully created tags and I can see the data is correct.
I have also successfully connected to my sql database.
My database already has tables and data.
I now want to be able to enter a record into a table sometimes at a time of day, and sometimes triggered by a tag.
I was able to create a named update query and send constants to the table for the purpose of testing. Now I want to replace a couple of those constants with tags.
Once I get that working, I need to be able to trigger that update query by time and also by a tag.
Thanks
I would look into transaction groups which are a part of the SQL Bridge module. Very handy for things like this, although you can still do it without it.
In named queries, you create parameters that can be tested with constant values. For tag values, you’ll read the tags, then feed the named query a dictionary based on that read.
# list of tags to read
tags = ['tagPath1','tagPath2']
# blocking read all tags in list
tag_reads = system.tag.readBlocking(tags)
# NQ dictionary from tag values
params = {'tag1':tag_reads[0].value, 'tag2':tag_reads[1].value}
# run query
result = system.db.runNamedQuery('queryPath',params)
Without the SQL bridge, you would create a scheduled gateway script for the time trigger, and a gateway tag change script for the tag change trigger. Create a project script that reads the tags and runs the query. Then call that project script from both scheduled and tag trigger scripts instead of duplicating code.
There is also tag history that you can enable in the tag configurations themselves.
I have no problem using transaction groups if that is the easiest, but the videos I watched on transaction groups just showed having the group create the table.
It’s an option, you can choose an existing table too. Make sure you check out all the associated videos on www.inductiveuniversity.com
Ok, i’m getting closer.
My table (ShotTotals) has an ID field that is primary key and it is auto number. I believe it is my hold up.
If I create an identical table (TestTotals) that does not have an ID field, then I can write my data to it using a Historical Transaction.
I have not been able to write to my ShotTotals table I think because of the ID field