I have a query tag that returns the result I am looking for. I don't need an array or anything, it is a single value. I want to write this into a global tag in my contrologix. Watching inductive university topics about query tags, at the bottom of the interface it looks like this used to be built in, because there was a checkbox with some drop downs where you could select the device and tag. This no longer exists. How do I accomplish this?
Just use a Tag valueChange Gateway Tag Change event, on the query tag, in combination with system.opc.writeValue()
to write the value to the PLC anytime the value changes.
Here is what I just tried and it didn't like it:
Select top 1 [NumericAnswer]
From [Horizon].[dbo].[SpecimenResult]
where [DefinitionID] = 55 and [NumericAnswer] is not NULL
order by [BatchID] Desc;
system.opc.writeValue([default]Inverter_Room/StartingStress)
Just that last line is what I changed. It worked fine without it.
That is because, what you did is not what I suggested.
Instead you tried to use a scripting function in your SQL, and that doesn't work.
Instead, you need to add the function to the valueChanged Gateway Tag Change Scripting event triggered by the tag.
Not safe in a tag valueChange event. That system call blocks, possibly for long time.
Use a gateway tag change event for such a script.
(Or, perhaps, use my Integration Toolkit's "Republish" tag actor, which works basically just like the old v7.9 functionality.)
Yeah, I'm not sure why I thought that was an Async function.
I have edited previous posts for a more appropriate solution.
Yes, you are using three variables in that script which have not been defined.
I handed out some poor advice, which has been corrected now. Sorry about that.
One way to approach this is to use a Gateway Tag Event Script:
You assign the query tag as a trigger tag, and then in the script you would use a script like this:
if not initialChange:
server = "Ignition OPC UA Server"
path = "OPC Path to the PLC Tag"
# newValue is pre-defined by the event. It will hold
# the new value of the tag which triggered the event. In this case
# the value of the query tag.
system.opc.writeValue(server,path,newValue.value)