Writing to a tag with scripting

I need help in scripting, I need to write the status of one tag to another. Here is what I have so far and it doesnt work. What am I missing? I am using 8.1.0

Context is important.

1.) Generally post the script using the preformatted text option, so that we can copy and paste your code into our posts to help you.

2.) You’ve clipped some rather important information out of your screen shot.

I see “event” in the doc string, but I don’t know what kind of event it is.

I also see value=currentValue so I’m assuming this is probably a tag event script. So here is my best guess as to what the real issue is, currentValue is a qualifiedValue object. You have to pull the actual value out of it.

Also, since this is Version 8.1, you should be using system.tag.writeBlocking()

Try this:

path = '[.]Tilter_Alarm/Siren_Alarm'
value = currentValue.value
system.tag.writeBlocking([path],value)

Or If you would all you really need is this:

system.tag.writeBlocking(['[.]Tilter_Alarm/Siren_Alarm'],currentValue.value)
2 Likes

here is the code. also i am trying to write the status of a boolean to another boolean, so when its true the other bool is true also.

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	"""
	Fired whenever the current value changes in value or quality.

	Arguments:
		tag: The source tag object. A read-only wrapper for obtaining tag
		     properties.
		tagPath: The full path to the tag (String)
		previousValue: The previous value. This is a "qualified value", so it
		               has value, quality, and timestamp properties.
		currentValue: The current value. This is a "qualified value", so it has
		              value, quality, and timestamp properties.
		initialChange: A boolean flag indicating whether this event is due to
		               the first execution or initial subscription.
		missedEvents: A flag indicating that some events have been skipped due
		              to event overflow.
	"""
	path="[.]Tilter_Alarm/Siren_Alarm.value]"
	value=currentValue
	system.tag.write(path, value)

There seems to be a couple of issues:

  1. You do not need the “.value” in the path
  2. Your path string has an extra “]” at the end

Also, when posting code, it’s preferable to post the text and not an image of the text.

Finally, at some point system.tag.write was deprecated, but I am not sure in what version. Ideally you should be using system.tag.readBlocking and system.tag.writeBlocking instead of system.tag.read and system.tag.write

2 Likes

I have tried both:

	path = '[.]Tilter_Alarm/Siren_Alarm'
	value = currentValue.value
	system.tag.writeBlocking([path],value)

and

system.tag.writeBlocking(['[.]Tilter_Alarm/Siren_Alarm'],currentValue.value)

Nether is resulting in when one bool is true the other is also true.
I apologize in advance for my ignorance

Are both of these OPC tags?

Have you considered using an Expression Tag, or a Derived Tag?

There is nothing incorrect with the code as I have written it, so it should work. That leaves only an incorrect path as the culprit.

How did you get the tag path?

the tag doing the write is a memory tag for test purposes, but will come from and OPC bool tag. The OPC bool tag is our plants weather alarms. The tag receiving the write is a bool that will sound an alarm in another part of our plant. the tag path was acquired by the tag icon in the top RH corner of the scripting pop-up.

system.tag.writeBlocking([path],value)

Is incorrect. In the writeBlocking version of the function, both the paths and the values are Python lists. So the correct call should be:

system.tag.writeBlocking([path],[value])

1 Like

should be:

system.tag.writeBlocking(['[.]Tilter_Alarm/Siren_Alarm'],[currentValue.value])

Also, you can look at the log on the Gateway web page to see if there are any warnings/errors…

I can get the above to write from a memory tag to another memory tag, but not to an OPC bool tag. Can an OPC bool only be written to by another OPC bool tag?

Nevermind that guys, not sure what I just did but I just got the memory tag to write to the bool tag

Oh boy, open mouth insert foot. :man_facepalming:

Oh well, I say “if you aint ever wrong, you aint learning”. lol

You really should mark @peter 's response as the solution, since he actually posted the correct code. That will help future readers the most.