64-Bit Double Little Endian Input Register

Returns Error_ExpressionEval("Error executing script for runScript() expression:ByteUtil.double_le2")
on the tag with the script "runScript("ByteUtil.double_le2", 0, {[~]1_IR30001})". I didn't change the tag name but the OPC address is ns=1;s=[RedMeter]1.IRI_6430001

The tags also return an Error_TypeConversion with the data type as Integer. It returns a number when set to Long, Float, or Double though.

I may have forgotten to save after entering the new function. It isn't giving an error now but the value is still extremely small. I'm still playing with it to see if I can bring in another register.

The IRI_64 is set as a Long currently and the expression tag is a Double.

My brain is embarrassing mush this morning. I can't be trusted with bit banging right now.

Try this:

def double_le2(value):
	from java.lang import Double
	b0 = (value >> 56) & 0xFF
	b1 = (value >> 48) & 0xFF
	b2 = (value >> 40) & 0xFF
	b3 = (value >> 32) & 0xFF
	b4 = (value >> 24) & 0xFF
	b5 = (value >> 16) & 0xFF
	b6 = (value >>  8) & 0xFF
	b7 = (value >>  0) & 0xFF
	
	return Double.longBitsToDouble(b0 | (b1 << 8) | (b2 << 16) | (b3 << 24) | (b4 << 32) | (b5 << 40) | (b6 << 48) | (b7 << 56))

Result should be 3.99 with the Long value from your screenshot.

1 Like

My HERO!!!

Ooph, insult to injury, making it harder on myself all along:

def double_le3(value):
	from java.lang import Long
	from java.lang import Double
	
	return Double.longBitsToDouble(Long.reverseBytes(value))

Stepping away from the computer before I do more damage :laughing:

3 Likes

That worked as well. Time for more coffee. Thanks again @Kevin.Herron