Hello community,
I'm having some trouble reading Modbus TCP addresses from an oxygen and methane sensor on an MSA device. The MSA device manual contains Modbus addresses in a specific format that I need to convert to see the actual value. Details of the format can be found here:
I'm using ModbusTester as a quick tool to visualize data. In ModbusTester, I have the option to change the format, which does give me the measured value (which appears on the device 20.8). So, how would I do it in Ignition?
I'm trying this code, but it doesn't update the value when the Modbus tags change. It's as if it only performs the calculation once and doesn't refresh when the Modbus tag values change.
def transform(self, value, quality, timestamp):
try:
high = self.custom.key1 & 0xFFFF # Tag 107
low = self.custom.key2 & 0xFFFF # Tag 106
# Change 32 bits
combined = (high << 16) | low
# read IEEE754 float (32 bits)
sign = -1 if (combined & 0x80000000) else 1
exponent = ((combined >> 23) & 0xFF) - 127
mantissa = combined & 0x7FFFFF
if exponent == -127:
result = sign * (mantissa / float(1 << 23)) * (2 ** (-126))
else:
result = sign * (1 + mantissa / float(1 << 23)) * (2 ** exponent)
return round(result, 3)
except:
return None