Alternative to BinEnc to return a float?

You would have to write it back to a different tag.

I would put the script in the global scripting project, modified slightly so you can write to a target tag, then call it from a tag event script on the the raw value tag.

def toFloat32(valIn, target):
	import struct
	
	# Swap endianness 
	valIn = struct.unpack("<I", struct.pack(">I", valIn))[0]

	# Return IEEE 754 float.
	floatOut = struct.unpack('f', struct.pack('I', valIn))[0]
	system.tag.writeBlocking([target], [floatOut])

In my example, I added a script to my global project called convert. The function resides in that script.

I made two tags in my test tag provider: RawValue and FloatValue. RawValue has the event script. in it.

	value = currentValue.value
	convert.toFloat32(value, '[Test]FloatValue')

2 Likes