Numeric Input convert value before writing to PLC

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.

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).

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)

Uggh. A classic circular reference.

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


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


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

1 Like

?? Try the 18th century:

Why would anyone want to go backwards?

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.

Haha, for simplicity and standardisation then

Is that response from GPT 3.5 or 4?

Not sure I trust everything out of 3.5...

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

1 Like

Most simple solution always wins. Face-palm

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.

1 Like

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?

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.

1 Like