# system.tag.writeBlocking returns good quality, but is not written to OPC tag

**URL:** <https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [September 29, 2020, 5:24pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195 "2020-09-29T17:24:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![alop150](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@alop150](https://forum.inductiveautomation.com/u/alop150)\
**Post date:** [September 29, 2020, 5:24pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/1 "2020-09-29T17:24:45Z")

</div>

Hello!, I have a gateway event which is triggered from a value change from an OPC tag, this event has a script to validate some functions and then write values on the OPC tags.  
Some times the function is not writteen to the tag; I already change the function .write to .writeBlocking, but the result its the same.  
Im not sure if someone has the same issue, and what I’m doing wrong,

Note: using the function .writeBlocking the results is always good, and I cant get any logs with a error.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 29, 2020, 9:41pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/2 "2020-09-29T21:41:24Z")

</div>

Can you post your script?

---

<div class="post-metadata">

**Author:** ![alop150](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@alop150](https://forum.inductiveautomation.com/u/alop150)\
**Post date:** [September 29, 2020, 9:52pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/3 "2020-09-29T21:52:56Z")

</div>

attached is the part where Im trying to write on the OPC tag

---

<div class="post-metadata">

**Author:** ![alop150](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@alop150](https://forum.inductiveautomation.com/u/alop150)\
**Post date:** [September 29, 2020, 9:56pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/4 "2020-09-29T21:56:41Z")

</div>

```auto
def SendStart(seqn):
	system.tag.write("[.]mensaje",GetCurrentmsg()+ "<br>-Funcion SendStart() ")
	ValueStart=bool(system.tag.read("[.]ValueStart").value)
	ValueStatus=system.tag.read("[.]ValueStatus").value
	system.tag.write("[.]mensaje",GetCurrentmsg()+ "<br>-Valores Enviados al PLC")
	result = system.tag.writeBlocking(["[.]start_PC","[.]status_PC"],[ValueStart,ValueStatus])
	system.tag.write("[.]mensaje",GetCurrentmsg()+ "<br>-Evalua Start: "+str(result))
	system.tag.write("[.]SeqNo",seqn+1)

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 30, 2020, 9:22pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/5 "2020-09-30T21:22:05Z")

</div>

You’ll need to edit and post it within a preformatted block. Python is unreadable without intact spacings

 ![Screenshot_20201001-065150_Chrome](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/e/be2f8063747b3353b269e560b4ff8017c1bd0071.jpeg)

However, I’d suggest instead of building your values to write within the function arguments, to write them into a variable which you pass in. It’ll make your life easier when it comes to diagnosing issues as you’ll know exactly what you’re passing into the functions and if they’re in fact valid. Then put a bunch of print statements to check the values

---

<div class="post-metadata">

**Author:** ![mike4](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mike4](https://forum.inductiveautomation.com/u/mike4)\
**Post date:** [October 12, 2022, 4:57pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/6 "2022-10-12T16:57:40Z")

</div>

I'm having the same issue with getting system.tag.writeBlocking working.

```auto
	tagPath = self.custom.TagPath
	print "tagpath: ", tagPath
	currentValue = system.tag.readBlocking(tagPath)[0].value
	print "tag value: ", currentValue
	if currentValue == 0:
		system.tag.writeBlocking([tagPath],[int(currentValue) | 1])
	elif currentValue == 1:
		system.tag.writeBlocking([tagPath],[int(currentValue) | 0])

```

No errors, tag status does not change.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 12, 2022, 5:00pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/7 "2022-10-12T17:00:53Z")

</div>

You're not checking for errors, how do you know there are none?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 12, 2022, 5:28pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/8 "2022-10-12T17:28:58Z")

</div>

> [@mike4](#):
>
> `int(currentValue) | 0`

What do you expect to happen with this? (Bitwise OR with zero changes nothing.)

---

<div class="post-metadata">

**Author:** ![mike4](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mike4](https://forum.inductiveautomation.com/u/mike4)\
**Post date:** [October 12, 2022, 5:51pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/9 "2022-10-12T17:51:57Z")

</div>

The goal is to simply write a boolean tag in the PLC to 1.

I changed the tagpath to a direct tag that I am monitoring in the Tag Browser.

```auto
	tagPath = "[default]DV/UTL/WW1/ALM/ALM_Injection_Alarm_TEST"
	print "tagpath: ", tagPath
	currentValue = system.tag.readBlocking(tagPath)[0].value
	print "tag value: ", currentValue
	if currentValue == 0:
		system.tag.writeBlocking("[default]DV/UTL/WW1/ALM/ALM_Injection_Alarm_TEST",[1])
	elif currentValue == 1:
		system.tag.writeBlocking("[default]DV/UTL/WW1/ALM/ALM_Injection_Alarm_TEST",[0])

```

I am following the examples in the ignition helpfile [Reading and Writing to Tags](https://docs.inductiveautomation.com/display/DOC80/Reading+and+Writing+to+Tags)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 12, 2022, 5:59pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/10 "2022-10-12T17:59:14Z")

</div>

```python
tagPath = "[default]DV/UTL/WW1/ALM/ALM_Injection_Alarm_TEST"
print "tagpath: ", tagPath
currentValue = system.tag.readBlocking(tagPath)[0].value
print "tag value: ", currentValue
result = system.tag.writeBlocking(["[default]DV/UTL/WW1/ALM/ALM_Injection_Alarm_TEST"], [not currentValue])

print result

```

You need to capture the result of `writeBlocking` to know if there's anything being reported as a problem.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 12, 2022, 6:18pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/11 "2022-10-12T18:18:37Z")

</div>

Boolean tags aren't 0 and 1. They are `True` and `False`. You can write 0 or 1 to them as a convenience, but your comparisons are broken. Replace the entire 4-line `if`-`elif` block with this:

```auto
system.tag.writeBlocking(["[default]DV/UTL/WW1/ALM/ALM_Injection_Alarm_TEST"], [not currentValue])

```

---

<div class="post-metadata">

**Author:** ![mike4](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mike4](https://forum.inductiveautomation.com/u/mike4)\
**Post date:** [October 12, 2022, 6:19pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/12 "2022-10-12T18:19:46Z")

</div>

That is a much simpler version of what I was trying to do.

Here is the working code block:

```auto
	tagPath = self.custom.TagPath	#[default]DV/UTL/WW1/ALM/ALM_TEST
	print "tagpath: ", tagPath
	currentValue = system.tag.readBlocking(tagPath)[0].value
	print "tag value: ", currentValue
	result = system.tag.writeBlocking([tagPath], [not currentValue])
	return result

```

---

<div class="post-metadata">

**Author:** ![mike4](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mike4](https://forum.inductiveautomation.com/u/mike4)\
**Post date:** [October 12, 2022, 6:40pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/13 "2022-10-12T18:40:39Z")

</div>

Why does this code not work? How can I check for a boolean?

```auto
	tagPath = self.custom.TagPath	#[default]DV/UTL/WW1/ALM/ALM_TEST
	print "tagpath: ", tagPath
	currentValue = system.tag.readBlocking(tagPath)[0].value
	print "tag value: ", currentValue
	if currentValue == "true":
		system.tag.writeBlocking(["tagPath"],[0])
	elif currentValue == "false":
		system.tag.writeBlocking(["tagPath"],[1])

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 12, 2022, 6:51pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/14 "2022-10-12T18:51:40Z")

</div>

`tagPath` is a variable named tagpath. `"tagPath"` is the literal string `tagPath`.

---

<div class="post-metadata">

**Author:** ![mike4](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mike4](https://forum.inductiveautomation.com/u/mike4)\
**Post date:** [October 12, 2022, 6:57pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/15 "2022-10-12T18:57:54Z")

</div>

I'm referring to the IF statement:  
How can I check if the boolean tag is true or false?

```auto
	if currentValue == "true":
		system.tag.writeBlocking(["tagPath"],[0])
	elif currentValue == "false":
		system.tag.writeBlocking(["tagPath"],[1])

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [October 12, 2022, 7:04pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/16 "2022-10-12T19:04:15Z")

</div>

You check for a boolean tag value being `True` or `False` like this:

```auto
if currentValue:
    system.tag.writeBlocking([tagPath],[False])
else:
    system.tag.writeBlocking([tagPath],[True])

```

However, since all you're wanting to do is invert the current value, then you don't need to "check" the value, just use the `not` keyword to invert the value.

```auto
system.tag.writeBlocking([tagPath],[not currentValue])

```

Which not coincidentally is exactly what @pturmel suggested.

Be careful with your tagPath references, I'm willing to bet that "tagPath" isn't a valid tag path. As @paul-griffith has pointed out.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 12, 2022, 7:14pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/17 "2022-10-12T19:14:22Z")

</div>

See the [Python docs](https://docs.python.org/2.7/reference/expressions.html#booleans):

> when expressions are used by control flow statements, the following values are interpreted as false: `False`, `None`, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets and frozensets). All other values are interpreted as true.

Python uses the singleton objects `True` and `False` for the boolean constants, unlike other languages which use `true` and `false` as constants.

So you _could_ write:  
`if currentValue == True:`  
And it would work just fine. But idiomatic Python tells you to drop the `== True`, because it's not really adding any clarity. You are obviously welcome to write your own code however you want, though 🙂

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 12, 2022, 7:28pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/18 "2022-10-12T19:28:51Z")

</div>

> [@paul-griffith](#):
>
> You are obviously welcome to write your own code however you want, though

And when you do, the pedants around here (like me) will ding you for it. 😏

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 13, 2022, 9:31am UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/19 "2022-10-13T09:31:14Z")

</div>

> [@pturmel](#):
>
> the pedants around here (like me)

I just know you're talking about me, your attempts at misdirection are futile.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 13, 2022, 12:18pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-returns-good-quality-but-is-not-written-to-opc-tag/39195/20 "2022-10-13T12:18:09Z")

</div>

> [@pascal.fragnoud](#):
>
> your attempts at misdirection are futile.

Ok. Caught me. I'm not a pedant. 😇
