Hi, is it possible to get a push button to increment an OPCUA tag with 10 each time the button is pressed?
Thanks
Hi, is it possible to get a push button to increment an OPCUA tag with 10 each time the button is pressed?
Thanks
I dont have a live OPC tag to test on so set up a memory tag to test..
On action performed on the button, create a script..... assuming perspective use.
value = system.tag.readBlocking(["Testing Tags/Your Tag"])[0].value
system.tag.writeBlocking(["Testing Tags/Your Tag"],[value + 10])
Edited to say, you may need to specify the provider depending how your tags are set up..
system.tag.readBlocking(["[default]My/Tag/Path"])
https://docs.inductiveautomation.com/display/DOC80/Reading+and+Writing+to+Tags
Thank you! This works. But it does take a few seconds to update though, is there any way to speed this up?
I'm not sure to be honest, On a memory tag its instant. One for the more qualified folks on here..
Since its a OPC tag, it may have something to do with the speed in which the tag updates, assuming the OPC tag is from a PLC or sensor or something ?
In general, values in OPC tags only come from the OPC subscription at the designated pace. Writes "pass through" to the device, and the tag's value is only updated when the next report comes from the OPC subscription.
A read/write directly to OPC is also an option,
https://docs.inductiveautomation.com/display/DOC81/system.opc.writeValue
Would this be easier if you bidirectionally bound a custom property to the Tag value and just incremented the custom property by 10 as needed? I don't know how much of a factor the read/write calls are in the execution time, and it really sounds like you're more at the mercy of the subscription rate.
That greatly simplifies the script but doesn't change the overall functionality significantly. If the write fails, the next subscription report after the write timeout will change the value back. You will also get the "write pending" overlay, which may or may not be helpful.
Not sure if the attached video will work. I VPN'd into one of my machines so I could test on a live OPC tag. No matter which way you do it, the result is still the same.
Tag Write..
value = system.tag.readBlocking(["[edge]New Tag"])[0].value
system.tag.writeBlocking(["[edge]New Tag"],[value + 10])
OPC Write
server = "PLC"
path = "nsu=http://PU-2C-001;i=843"
oldQualifiedValue = system.opc.readValue(server, path)
newValue = oldQualifiedValue.getValue() + 10
returnQuality = system.opc.writeValue(server, path, newValue)
Bi-Directional
self.custom.Tag = self.custom.Tag + 10
What're the Tag Group settings that your tag is part of?
You could turn on read after writing or optimistic writes to force it to immediately assume the write went through and use the write value.