Your script does not do anything. ?It is getting and setting the JMRI turnout state which does not change anything.
It appears that your goal is to get the "layout" turnout state and set the JMRI turnout state to that value. ?The ability to that depends on the layout hardware including the command station, switch machines, turnout feedback, etc.
The easiest and most reliable approach is for JMRI to initialize the turnouts to a known state.
Dave Sand
toggle quoted message
Show quoted text
----- Original message -----
Subject: Re: [jmriusers] NCE Accessory Event Monitoring and possibly CS-105
Date: Wednesday, January 08, 2025 9:10 AM
Also I was attempting to draft a script that would ping each turnout in JMRI and return its current state. I note that the first time I touch the turnout icon in Panel Pro Main Panel, the turnout will first change color to its actual state. If I touch a second time it will physically change its state. Therefore, I was looking for a way to poll each turnout (without changing its position) and update Panel Pro Main Panel accordingly.
?
In Visual Studio Code with Copilot (ChatGPT) tried this code but I did not work. UpdateTurnoutState function was supposed to read state and then set turnout to that state without changing it - simulating what happens when you touch the screen once and it updates.
?
class setStartup(jmri.jmrit.automat.AbstractAutomaton) :
? ? def init(self):
? ? ? ? self.turnouts = jmri.InstanceManager.getDefault(jmri.TurnoutManager)
? ? ? ? return
? ??
? ? def handle(self):
? ? ? ? self.waitMsec(500)
? ? ? ? self.updateTurnoutState("1001")
? ? ? ? self.waitMsec(500)
? ? ? ? self.updateTurnoutState("1002")
# repeat for as many turnouts
?
? ? ?def updateTurnoutState(self, turnoutId):
? ? ? ? turnout = self.turnouts.provideTurnout(turnoutId)
? ? ? ? currentState = turnout.getState()
? ? ? ? turnout.setState(currentState)
?
?