Documentation > nControl > API Reference
Introduction
The train detection sensor emits IR light and measures the amount of light that is reflected back.
When the amount of detected IR light crosses the threshold level, the tile executes the trigger event script.
When the sensor value exceeds the trigger level it switches to the 'triggered' state and remains idle for a specified interval, i.e. the idle time.
During the idle time, the tile ignores the sensor value and remains in the triggered state. The idle time prevents multiple trigger events due to signal noise.
The tile can execute custom operations, like controlling track switches or traffic lights, during the ilde time.
After the idle time has passed the tile will move back to the untriggered state once the sensor value drops below the threshold.
When the tile comes out of the triggered state it will execute the reactivate script, if one exits.
Event Scripts
Sensor tiles support the following event scripts:
API Functions
Tile Specific Functions
nTrainSensorTile.disable()
Disables the sensor tile.
When being disable, the sensor no longer provides feedback, does not trigger any events and put the timers on hold until it's enabled again.
Disabling sensors can be useful to prevent false trigger events when a train parks in front of a sensor.
nTrainSensorTile.enable()
Re-enables the sensor tile after is has been disabled with the .disable() command.
nTrainSensorTile.enroll()
Enrolls the tile to receive serial feedback from a generic controller.
nTrainSensorTile.getIdleTime()
Returns the idle time setting of the tile. The idle time is specified in seconds.
nTrainSensorTile.getSerialData()
Returns the serial data received from a generic controller when a Serial Data event is triggered.
nTrainSensorTile.getThreshold()
Returns the current threshold level of the tile, expressed in percentage [0-100].
nTrainSensorTile.getValue()
Returns the value of the sensor when it triggered, expressed in percentage [0-100].
nTrainSensorTile.isTriggered()
Returns a boolean value indicating whether the tile is in triggered state or not.
nTrainSensorTile.publish(topic, data)
Publishes a message through the internal MQTT broker using the specified topic and data.
nTrainSensorTile.setIdleTime()
Sets the idle time of the sensor. The idle time is expressed in seconds.
nTrainSensorTile.setValue(value, scale=100)
Sets the value of the sensor tile in case your reading the sensor feedback with a generic controller, e.g. Arduino board.
nTrainSensorTile.setThreshold()
Sets the threshold value of the sensor tile. The threshold is expressed in percentage [0-100].
nTrainSensorTile.sinceReactivation()
Returns the number of seconds elapsed since the last time the sensor was reactivated.
nTrainSensorTile.sinceTrigger()
Returns the number of seconds elapsed since the last time the sensor was triggered.
Inherited from nTile
nTrainSensorTile.clearScreen() Clear all the text in the console window. nTrainSensorTile.getTile(label) Returns the tile object specified by label. If there is no tile with the specified label, the function returns a None value. nTrainSensorTile.print(text) Prints text in the console window. If the console window it not yet visible, printing text will make it visible. nTrainSensorTile.showConsole(mode) Shows (mode = True) or hides (mode = False) the console window. nTrainSensorTile.sleep(duration) Stops the execution of the script for the the given number of seconds. Note that duration can be a floating point number, e.g. to suspend the script for half a seconds use self.sleep(0.5). nTrainSensorTile.timestamp() Returns the number of seconds that passed since nControl™ was launched. It returns a floating point value with the highest possible time resolution supported by your system. The difference between two time stamps provides the number of seconds elapsed between those two events. nTrainSensorTile.localVars Base property to which you can add local variables that retain their value after the event script finishes. For example self.localVars.myVar = 5 adds a new property myVar to self.localVars and gives it the value 5. The localVars property is local to the current tile meaning that each tile has its own independent localVars property. nTrainSensorTile.globalVars Base property to which you can add global variables that retain their value after the event script finishes. For example self.globalVars.myVar = 5 adds a new property myVar to self.globalVars and gives it the value 5. The globalVars property is global to nControl meaning that all tiles use the same globalVars property. As such globalVars can be used to exchange information between the tiles. |