So i have a word where each bit represents an alarm from a different compartment the problem is that it keeps recording non existent alarms.
Here is the script i put on tag change:
#Exit if tag quality bad
if not (previousValue.quality.isGood() and currentValue.quality.isGood()):
return 0
# Calculate the bits that changed using XOR
changedBits = previousValue.value ^ currentValue.value
# Initialize lists to store the changes
true_changes = []
false_changes = []
# Loop over each bit position (0 to 15 for 16 bits)
for i in range(16):
# Check if the ith bit has changed by checking the corresponding bit in changedBits
bit_changed = (changedBits >> i) & 1
if bit_changed:
# Check the state of the bit in the current value
isTrue = (currentValue.value >> i) & 1
# Append to the appropriate list based on whether the bit has changed and its current value
if isTrue:
true_changes.append(i)
else:
false_changes.append(i)
for Num in true_changes:
system.db.runNamedQuery("SMP_Caster", "EAF/BAGH Event Start", {
"Equipment": "Compartment",
"BH": tagPath.rsplit('/', 1)[0][-1],
"Num": Num,
"Event": "BLD"
})
for Num in false_changes:
system.db.runNamedQuery("SMP_Caster", "EAF/BAGH Event End", {
"Equipment": "Compartment",
"BH": tagPath.rsplit('/', 1)[0][-1],
"Num": Num,
"Event": "BLD"
})