TIm,
Create SensndExample_1.py file from the test code below the ** , save it in your directory C:/Users/tim_p/sounds/Peter/
In Panel Pro, Panel, select Run Script - go to the Peter directory and run the SensndExample_1.py. Python is now running in the background.
Go to Tools, Table Sensor and create sensor 473 in my case I used LS473
When its created just click the active button and listen. Click the inactive button it silent.
In the if statement you can see where the playback is in a loop via the...... snd.loop() command. that the active/inactive states are registered.?
Now you can replace the "Crossing.wav" with your General01.wav and link the sensor representing the station. Step by step you can get this going.
I can believe how much time I wasted on an indentation issue in the original file. When you posted up your log I thought duh!!? Looked at the log and found the dent space, the file worked.?
It would be crazy to do the coding outside of JMRI when its already done. Thanks for the question as it got me to do something I should have done long time ago. ? ?
Inobu
*
?? # It listens for changes to a sensor,
# and then plays a sound file when sensor active
import jarray
import jmri
# create the sound object by loading a file
snd = jmri.jmrit.Sound("resources/sounds/Crossing.wav")
class SensndExample(jmri.jmrit.automat.Siglet) :
??????? # Modify this to define all of your turnouts, sensors and
??????? # signal heads.
??????? def defineIO(self):
???????????????
??????????????? # get the sensor
??????????????? self.Sen1Sensor = sensors.provideSensor("LS473")
???????????????????????????????
??????????????? # Register the inputs so setOutput will be called when needed.
??????????????? self.setInputs(jarray.array([self.Sen1Sensor], jmri.NamedBean))
??????????????? return
??????? # setOutput is called when one of the inputs changes, and is
??????? # responsible for setting the correct output
??????? #
??????? # Modify this to do your calculation.
??????? def setOutput(self):
???????????????????????????????
??????????????? if self.Sen1Sensor.knownState==INACTIVE:
??????????????????????? snd.stop()
??????????????? elif self.Sen1Sensor.knownState==ACTIVE:
??????????????????????? snd.loop()
???????????????
??????????????? return
???????
# end of class definition
# start one of these up
SensndExample().start()