¿ªÔÆÌåÓý

Locked Re: Scripting question - how to check if sensor or turnout name is valid


 

By chance is there an "ifExist" function available and a table of existing sensor/turnout names that it could test?


On Thu, Sep 5, 2019, 14:19 Pete Brownlow <merg@...> wrote:
I've put together a script that takes a sensor or turnout name in from an external program and operates the given sensor or turnout.

This works fine when the sensor or turnout name is valid - I use provideSensor or ProvideTurnout on the passed name, then set the active state.

However, if the external program passes in an invalid sensor or turnout name, then my script crashes out with an invalid name exception when trying to do:

mysensor = sensors.provideSensor( passedSensorName )

or

myturnout = turnotus.provideSensor( passedTurnoutName )

Does anyone have a code snippet to show me how to check if passedSensorName or passedTurnoutName is a valid user name in the sensor or turnout table respectively, before I try the call to provide?

(I'm assuming that Jython still has no way of error trapping and handling in the script)

Thanks,

Pete

Join [email protected] to automatically receive all group messages.