# Writing value to tag from expression tag

**URL:** <https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151>\
**Category:** Ignition\
**Created:** [August 20, 2021, 7:08pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151 "2021-08-20T19:08:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [August 20, 2021, 7:08pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/1 "2021-08-20T19:08:36Z")

</div>

I have an expression tag which simply takes the current time in seconds. I want to write this value to an OPC tag. I have the expression tag correctly updating based on the seconds. I read you could set an OPC tag directly from this tag but can’t seem to figure out how to do it. It almost looks like you could do it in an earlier version of ignition but not anymore? I tried writing a Value changed event script to write the value of the expression tag to an OPC tag but no luck.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/b/1be37829e43dc2f376a6ed6f5a520c40be453f8a.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/6/964b43b16209a4984a4ada48b452441751eb34ee.png)

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [August 20, 2021, 8:17pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/2 "2021-08-20T20:17:41Z")

</div>

You should be able to do this with a gateway tag change script for your currentseconds tag.

```auto
system.tag.write("ScadaHeartbeat",newValue.value)

```

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [August 20, 2021, 8:35pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/3 "2021-08-20T20:35:03Z")

</div>

sounds good but I would rather do it with the UDT. I have six identical machines and would like to keep it within that machine UDT. I dont understand why this wouldn’t work?

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [August 20, 2021, 8:37pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/4 "2021-08-20T20:37:04Z")

</div>

I don’t have enough experience with UDT’s to answer that one, hopefully someone who does will chime in.

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [August 20, 2021, 8:49pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/5 "2021-08-20T20:49:53Z")

</div>

It seems as if the script if dead on and should be changing the tag. I have a simulator set up and can change the value of the tag from the plc. If I try to change it from Ignition I get the following:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/9/8991c79ec9fec6220ca590030b2f8c5b20d67242.png).  
I had the tag in the plc set to read/write and tried changing it to read only. The scadaheartbeat tag is set to read/write. Is it a matter of the tag only able to change values from the plc and that is why no matter what I do the value of the tag within ignition won’t change?

---

<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:** [August 20, 2021, 8:52pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/6 "2021-08-20T20:52:44Z")

</div>

Can you write to the scada heartbeat tag manually?  
Also, I don’t mean to preach, but I would consider reviewing the tag names in that UDT as you have a mix of at least 4 different standards (snake\_case, Capital\_Snake\_Case, Title Case, and PascalCase) which will most certainly trip you up while developing the graphics

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [August 20, 2021, 8:58pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/7 "2021-08-20T20:58:48Z")

</div>

Anytime I try to change the value manually I get that error. I just created a memory tag and changed the Value changed event script to write to the memory tag it works perfect. For some reason I am not able to write to the OPC tag. I tried deleting the tag and recreating it again within the UDT. The security is set to be able to read and write to it

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/b/1bbb86da61b213a8949c21a4d1a9c1b4f06ba765.png)

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [August 20, 2021, 9:00pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/8 "2021-08-20T21:00:28Z")

</div>

I agree. This was my first project and someone else helped so things weren’t uniform but next project I will be more consistent

---

<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:** [August 20, 2021, 9:01pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/9 "2021-08-20T21:01:11Z")

</div>

Is the OPC tag from the Ignition server? If so, what driver?

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [August 20, 2021, 9:03pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/10 "2021-08-20T21:03:30Z")

</div>

Yes it is from the Ignition server. The driver is the Allen-Bradley Logix Driver. I am on version 8.0.14 of Ignition.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/3/93ff4cebf78979117ab3ee85e6d08e3bd066b5d6.png)

---

<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:** [August 20, 2021, 9:05pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/11 "2021-08-20T21:05:19Z")

</div>

Turn the logger `drivers.LogixDriver.Requests.WriteTagsRequest` to DEBUG, attempt the write again, and post the error you see in the gateway logs.

[https://docs.inductiveautomation.com/display/DOC81/Diagnostics+-+Logs#DiagnosticsLogs-ChangingLoggingLevels](https://docs.inductiveautomation.com/display/DOC81/Diagnostics+-+Logs#DiagnosticsLogs-ChangingLoggingLevels)

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [August 20, 2021, 9:33pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/12 "2021-08-20T21:33:56Z")

</div>

While waiting for response I went ahead and change tag on plc side from Read/Write to Read Only. Then changed it back to Read/Write. Then went ahead and changed logs like above. I then tried to change the value manually through ignition and it didn’t give me the error but it didn’t change the value at all when I try to manually change it so I didnt get anything in the logs.

Now if I change it through the plc it changes. If I then try to change it in ignition, not matter what I put, it always changes the value in ignition and the plc to 1. Weirdest thing I have ever seen.

---

<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:** [August 20, 2021, 9:36pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/13 "2021-08-20T21:36:35Z")

</div>

Do you have your designer set to read/write comms? Do you have the right data type set in the tag?

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [August 20, 2021, 9:40pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/14 "2021-08-20T21:40:48Z")

</div>

I do. Now I went ahead and created a new tag in plc called heartbeat but made it a DINT. I then created the tag in ignition in my UDT called heartbeat and made it a double. Literally the same as the other tag except the only difference is the type. Now I can change it in plc and gets changed in ignition. Also if I change it in ignition it now changes and value also gets changed in plc.

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [August 20, 2021, 9:41pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/15 "2021-08-20T21:41:32Z")

</div>

As far as datatype I am only looking for numbers between 0 and 59 so INT should work

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [August 20, 2021, 9:47pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/16 "2021-08-20T21:47:01Z")

</div>

This is the code I have in the plc. The plc isn’t writing to this tag at all.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/c/4ce7cf4223c80527be29201c3ad46b4922f864b6.png)

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [August 20, 2021, 10:01pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/17 "2021-08-20T22:01:06Z")

</div>

Thank god its Friday. Essentially started from scratch. Erased plc code. Deleted Scada\_Heartbeat tag from plc. Erased from ignition. Created new plc tag called Heartbeat\_Scada in plc. Created new ignition tag called Scada\_Heartbeat and saved as a memory tag. Wrote the value changed script on currentseconds and the Scada\_Heartbeat ignition tag correctly updated. Then changed Scada\_Heartbeat tag from memory to OPC tag and linked to Heartbeat\_Scada tag in plc. Everything is now working…WTH???

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 20, 2021, 11:15pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/18 "2021-08-20T23:15:29Z")

</div>

You obviously had something wrong. 😁

---

<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:** [August 21, 2021, 1:39am UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/19 "2021-08-21T01:39:48Z")

</div>

In the screenshot, you have the sense of Ignition\_Comms\_Faulted\_Tmr backwards. The DN bit is **ON** when Scada\_Heartbeat is steadily changing.

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [August 23, 2021, 1:03pm UTC](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151/20 "2021-08-23T13:03:48Z")

</div>

I think you are correct…when people tell me the code just started going haywire…99.9999% of the time its not when its worked for the last 5 years…glad the ignition side is working now haha

[Next page](https://forum.inductiveautomation.com/t/writing-value-to-tag-from-expression-tag/50151.md?page=2)
