Is there any way to take a tag value in a PLC and write that value to a new tag and a different value? For example, say the tag in the PLC = 0 and I want the new tag to = recipe1. Or the the in the PLC = 1 and I want the new tag to = recipe2?
Yes there is. Depending on exactly what you want to do, you can read and write from the PLC directly through the system.opc.readValue and system.opc.writeValue or you can read and write to OPC Tags via the system.tag.read and system.tag.write.
Just depends on what you’re wanting to trigger this process, which is information you haven’t provided.
I am wanting to use the new tag to set a recipe with a recipe selector. By doing this I need to have the tag value the same as the recipe in the recipe selector. So when the value for the recipe name in the PLC is set, I am needing to change that value to the value of the recipe.
No offense but that was kind of confusing for me.
However, I believe that what you are trying to say is you want to respond to a change in a PLC tag value, by changing another tag indicating the recipe value. If that is the case I believe you are looking for the valueChanged event on OPC tags. You can find more information on that here.
I think I follow you. Another way you can do it is setup an expression tag and enable OPC write back.
The expression would monitor either the string or integer value and then resolve to the corresponding value and write this back to an OPC tag. I do have a question though, are both of these tags in the PLC? Is there any reason the PLC can’t do this?
One tag is, it is the tag that selects the recipe in the PLC. But the recipe value in the PLC sets with a 0, 1, 2… and so on. I’m wanting to use those values and convert them to the names of the recipes in the recipe selector (“Recipe 1”, “Recipe 2” and so on.)