# Numeric Input convert value before writing to PLC

**URL:** <https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 9, 2023, 7:27pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494 "2023-05-09T19:27:15Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aaron\_Shivnen](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@Aaron\_Shivnen](https://forum.inductiveautomation.com/u/Aaron_Shivnen)\
**Post date:** [May 9, 2023, 7:27pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/1 "2023-05-09T19:27:16Z")

</div>

I have a system that takes coordinates from an Input on an HMI (perspective Edge). The coordinates are input as mm and in the PLC everything is in mm as well. However for my operators everything is inches. I am trying to setup a numeric entry field that will allow the operator to input Inches, I then convert to mm to send to the PLC.

On the screen my Numeric Entry component is bond to a Tag (PLC). With an expression transform:  
This converts the PLC tag values to Inches.

```auto
round(({value} / 25.4), 3)

```

On the same component I have a property change script tied to the value property.  
This script is working but I get a feedback loop effect, where after a change is made the PLC tag updates and causes the value property to change again (due to the binding and transform).

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	memtag = ["[edge]aLuxwall/Recipe/lengthMem"]
	mmtag = ["[edge]HMI_PART_LENGTH/DINT_IN.value"]
	
	mem = system.tag.readBlocking(memtag)
	mm_cur = system.tag.readBlocking(mmtag)
	mm_val = mm_cur[0].value
	mem_val = mem[0].value
	
	value = self.props.value
	mm = value * 25.4
	mm_new = int(mm)
	
	if currentValue.value != mem_val:
	#if previousValue.value != mem_val:
	
			system.tag.writeBlocking(mmtag, mm_new)
			system.tag.writeBlocking(memtag, value)

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 9, 2023, 7:43pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/2 "2023-05-09T19:43:08Z")

</div>

> [@Aaron\_Shivnen](#):
>
> get a feedback loop

Uggh. A classic circular reference.

---

<div class="post-metadata">

**Author:** ![Ryan\_Allen](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_allen/32/47013_2.png) [@Ryan\_Allen](https://forum.inductiveautomation.com/u/Ryan_Allen)\
**Post date:** [May 9, 2023, 7:43pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/3 "2023-05-09T19:43:26Z")

</div>

Cant you just set the scaling on the tag? 0-1 inch = 0-25.4 mm

---

<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:** [May 9, 2023, 7:46pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/4 "2023-05-09T19:46:31Z")

</div>

This is one of the kinds of problems Derived Tags were conceived to solve.

---

<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:** [May 9, 2023, 9:00pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/5 "2023-05-09T21:00:28Z")

</div>

> [@Aaron\_Shivnen](#):
>
> However for my operators everything is inches

Maybe introduce your operators to the 21st century and use the metric system? 😁 (yes, I poked that beast)

---

<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:** [May 9, 2023, 9:04pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/6 "2023-05-09T21:04:30Z")

</div>

> [@nminchin](#):
>
> the 21st century

?? Try the _ **18th** _ century:

> **[History of the metric system](https://en.wikipedia.org/wiki/History_of_the_metric_system)**
>
> The history of the metric system began during the Age of Enlightenment with measures of length and weight derived from nature, along with their decimal multiples and fractions. The system became the standard of France and Europe within half a century. Other measures with unity ratios\[Note 1\] were added, and the system went on to be adopted across the world.
> The first practical realisation of the metric system came in 1799, during the French Revolution, after the existing system of measures ha...

Why would anyone want to go backwards?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 9, 2023, 9:13pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/7 "2023-05-09T21:13:00Z")

</div>

Yup, it was the French that stuck us yet another base 10 measurement system. There is a strong case that base 12 would have been much better.

---

<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:** [May 9, 2023, 9:13pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/8 "2023-05-09T21:13:03Z")

</div>

Haha, for simplicity and standardisation then

 ![Screenshot_20230510_063856_Chrome](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/4/64be6ecf873da8a049758845cee77bfe0ce62e87.jpeg)

---

<div class="post-metadata">

**Author:** ![Aaron\_Shivnen](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@Aaron\_Shivnen](https://forum.inductiveautomation.com/u/Aaron_Shivnen)\
**Post date:** [May 9, 2023, 9:17pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/9 "2023-05-09T21:17:51Z")

</div>

Is that response from GPT 3.5 or 4?

Not sure I trust everything out of 3.5...

---

<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:** [May 9, 2023, 9:22pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/10 "2023-05-09T21:22:54Z")

</div>

3.5, and neither do i, but I think this response to my question to it is fairly generally acknowledged across the world

---

<div class="post-metadata">

**Author:** ![Aaron\_Shivnen](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@Aaron\_Shivnen](https://forum.inductiveautomation.com/u/Aaron_Shivnen)\
**Post date:** [May 9, 2023, 9:24pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/11 "2023-05-09T21:24:30Z")

</div>

Most simple solution always wins. Face-palm

---

<div class="post-metadata">

**Author:** ![Aaron\_Shivnen](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@Aaron\_Shivnen](https://forum.inductiveautomation.com/u/Aaron_Shivnen)\
**Post date:** [May 9, 2023, 9:25pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/12 "2023-05-09T21:25:50Z")

</div>

I have not used Derived Tags ever. @Ryan_Allen idea was simple and correct, except for one minor detail. My inch dimensions can be a float, like 18.125 (18 1/8 in) and my coordinate tag is a DINT.

I'll check into derived tags tomorrow.

---

<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:** [May 9, 2023, 9:29pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/13 "2023-05-09T21:29:00Z")

</div>

I wonder what the more efficient way to do unit swapping in clients would be: using multiple opc tags with different scaling ans displaying one or the other, or using a single opc tag with derived tags for other units?

---

<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:** [May 9, 2023, 9:33pm UTC](https://forum.inductiveautomation.com/t/numeric-input-convert-value-before-writing-to-plc/73494/14 "2023-05-09T21:33:34Z")

</div>

Scaling works here too because it's a linear conversion.

You can't use scaling for something like bi-di conversion from F to C, but Derived Tags work great there.
