Documentation > nControl > API Reference
Introduction
The tile has three mouse click zones and the function that is performed depends on the zone
that is clicked: stop(), goLeft() or goRight(). You can override the default
function by a custom procedure.
Event Scripts
Monoswitch tiles support the following event scripts:
API Functions
Tile Specific Functions
nMonorailMonoswitch.clickTile(zone)
Simulates a mouse click on the tile; this executes the mouse click event script.
The argument zone specifies the mouse click zone where the virtual click appeared:
nMonorailMonoswitch.getMouseClickZone()
Returns the zone that received the last mouse click:
nMonorailMonoswitch.getMouseClickZoneState()
Returns the state associated with the zone that received the last mouse click:
nMonorailMonoswitch.getState()
Returns the current state of the monoswitch control: or nConst.MS_LEFT, or nConst.MS_RIGHT
or or nConst.MS_STOP
nMonorailMonoswitch.goLeft()
Puts the monoswitch in the 'go left' position.
nMonorailMonoswitch.goRandom(left=1, right=1)
Puts the monoswitch in a random direction: go left or go right.
The arguments left and right can be used to customize the probability of going left or right.
If left = right both directions have the same probability.
If left = 2 and right = 1 the change of going left is twice as high as the chance of going right.
nMonorailMonoswitch.goRight()
Puts the monoswitch in the 'go right' position.
nMonorailMonoswitch.publish(topic, data)
Publishes a message through the internal MQTT broker using the specified topic and data.
nMonorailMonoswitch.setState(state)
Sets the state of the monoswitch: nConst.MS_LEFT, nConst.MS_RIGHT
or or nConst.MS_STOP.
nMonorailMonoswitch.stop()
Puts the monoswitch in the 'stop' position.
Inherited from nTile
nMonorailMonoswitch.clearScreen() Clear all the text in the console window. nMonorailMonoswitch.getTile(label) Returns the tile object specified by label. If there is no tile with the specified label, the function returns a None value. nMonorailMonoswitch.print(text) Prints text in the console window. If the console window it not yet visible, printing text will make it visible. nMonorailMonoswitch.showConsole(mode) Shows (mode = True) or hides (mode = False) the console window. nMonorailMonoswitch.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). nMonorailMonoswitch.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. nMonorailMonoswitch.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. nMonorailMonoswitch.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. |