Im working on making an audible alarm system triggered when any Active Unacknowledged alarm is present. I have a sound player placed on my navigation window so it will be present no matter what page im on. I have two custom properties on the sound player. First, “alarmCount” which is bound to the system gateway tag value for Active Unacknowledged alarms. Second, “enableAudio” is simply a Boolean value used to turn the script on and if for testing purposes. So overall the script works well. The issue is that the .wav file will fire off multiple times when the sound player is triggered. I have placed a print statement to verify that the sound will fire more than once. Is there a way I can prevent the file from playing more than once? I’m a novice at coding, so I’m curious if there is a method or command that can prevent this from happening. Also, I must keep the sound on loop because the whole idea is to keep the sound playing as long as there is any active unacknowledged alarms. The sound is a short one 3 second alarm sound.
Code Example:
This script enabled an audible sound if any Active alarm is unacknowledged.
The Custom Property “alarmCount” if bound to the System Gateway Active Unacknowledged alarm count.
The enableAudio Custom Property is simplay there as a handle to turn the script ON/OFF.
The alarms variable stores the Active Unacknowledged value to refrence.
Is that script on a propertyChange event? If so, you need to indent everything within an if block that checks event.propertyName. In Vision, all the properties of a component run through the same script.
I reformatted the code snippet and removed the comments so its easier to read. I thought I had all of the proper indentation needed to satisfy the text formatting. Is the indentation of the event.propertyName effected even if the formatting has no errors?
The code in a Vision propertyChange event should always look something like this:
if event.propertyName=='alarmCount':
audibleEnabled = event.source.enableAudio
alarms = event.source.alarmCount
if audibleEnabled == True:
if alarms > 0:
alarmEnabled = True
else:
alarmEnabled = False
if alarmEnabled == True:
event.source.trigger = True
print "Fire Sound"
else:
event.source.trigger = False
Note that assigning to event.source.trigger itself causes a recursive call to the propertyChange script (this time with “trigger” in event.propertyName). You are lucky your failure to check the propertyName didn’t give you an infinite loop and crash your designer.
Just to be clear: you didn’t have a syntax error. You had a logic error.
I understand now. I should have been more explicit in checking the exact property of that component. If another value changed from a different property, it would have also caused the sound player to trigger. I tested out the code snippet you sent back and the problem has been corrected. I will keep this in mind in the future. Thank you for your help. I really appreciate it.