User Tools

Site Tools


micha68:extkeyboardscript-en

Controlling Rocrail with external push-buttons and LEDs using XML Scripts

Assignment

To use Rocrail without Rocview - eg when operating only a Raspi or similar device as a server - you need to install push-buttons for entering commands (using sensors) and LED status indicators (using outputs).

I implemented that on my system via an IO module (OneControl from BiDiB system) with some actions.
Six push-buttons with built-in LEDs are used to turn a booster on and off; to activate and deactivate the auto mode; and to start and stop the locomotives.
The LEDs in the push-buttons indicate the current state.

XML-scripts, instead of Actions provide a significant simplification of the task.
Only 2 Actions are needed to trigger two XML-scripts.
An XML-script that is invoked at system startup (System Action / init) that sets the outputs (LEDs) in the initial state.
A second XML-script, which is located on all push-buttons as action and depending on the push-button, triggers appropriate system actions.

In the actual layout plan (plan.xml), the sensors for the push-buttons and the LED outputs are created.

XML-Scripts

Here is the script for evaluating of the push-buttons

<xmlscript>
<!-- Control of Rocrail with external push-buttons with LEDs for status indication -->
<!-- Push-button 1, ID=T1, Funktion= Power On     -->
<!-- Push-button 2, ID=T2, Funktion= Power Off    -->
<!-- Push-button 3, ID=T3, Funktion= Auto On      -->
<!-- Push-button 4, ID=T4, Funktion= Auto Off     -->
<!-- Push-button 5, ID=T5, Funktion= Loks starten -->
<!-- Push-button 6, ID=T6, Funktion= Loks stoppen -->
 
<!-- LED 1, ID=L1, Display= Power On         -->
<!-- LED 2, ID=L2, Display= Power Off        -->
<!-- LED 3, ID=L3, Display= Auto On          -->
<!-- LED 4, ID=L4, Display= Auto Off         -->
<!-- LED 5, ID=L5, Display= Loks starts      -->
<!-- LED 6, ID=L6, Display= Loks stops       -->
 
<!-- Push-button 1 = Power ON -->
<if state="fb T1 = true">
	<then>
		<!--   Power OFF? -->
		<if state="co L2 = on">
			<then>
			<co id="L1" cmd="on"/>
			<co id="L2" cmd="off"/>
			<sys cmd="go"/>
			<exit/>
			</then>
		</if>	
	</then>
</if>
 
<!-- Push-button 2 = Power OFF -->
<if state="fb T2 = true">
	<then>
		<!--  Power ON? -->
		<if state="co L1 = on">
			<then>
			<co id="L2" cmd="on"/>
			<co id="L1" cmd="off"/>
			<sys cmd="stop"/>
			<exit/>
			</then>
		</if>	
	</then>
</if>
 
<!-- Push-button 3 = AutoMode ON -->
<if state="fb T3 = true">
	<then>
		<!-- AutoMode OFF? -->
		<if state="co L4 = on">
			<then>
			<co id="L3" cmd="on"/>
			<co id="L4" cmd="off"/>
			<auto cmd="on"/>
			<exit/>
			</then>
		</if>	
	</then>
</if>
 
<!-- Push-button 4 = AutoMode OFF -->
<if state="fb T4 = true">
	<then>
		<!-- AutoMode ON? -->	
		<if state="co L3 = on">
			<then>
			<co id="L4" cmd="on"/>
			<co id="L3" cmd="off"/>
			<!-- Reset LED for Loc Start/Stop -->
			<co id="L5" cmd="off"/>
			<co id="L6" cmd="on"/>
			<auto cmd="off"/>
			<exit/>
			</then>
		</if>	
	</then>
</if>
 
<!-- Push-button 5 = Locs start -->
<if state="fb T5 = true">
	<then>
		<!-- Ist AutoMode AN? -->
		<if state="co L3 = on">
			<then>	
			<!-- Are Locs stopped? -->	
			<if state="co L6 = on">
				<then>
				<co id="L5" cmd="on"/>
				<co id="L6" cmd="off"/>
				<auto cmd="start"/>
				<exit/>
				</then>
			</if>
			</then>
		</if>	
	</then>
</if>
 
<!-- Push-button 6 = Loks stop -->
<if state="fb T6 = true">
	<then>
		<!-- Are Locs started? -->	
		<if state="co L5 = on">
			<then>
			<co id="L5" cmd="off"/>
			<co id="L6" cmd="on"/>
			<auto cmd="stop"/>
			<exit/>
			</then>
		</if>
	</then>
</if>
 
</xmlscript>


Before an action is performed, a check is made to insure that the desired state has not been set.
"Start all locomotives" is possible only, if previously the Auto Mode is set to On.

Here is the script for initializing the LEDs at startup

<xmlscript>
<!-- Initialize the LEDs. INIT -->
 
<co id="L1" cmd="off"/>
<co id="L2" cmd="on"/>
<co id="L3" cmd="off"/>
<co id="L4" cmd="on"/>
<co id="L5" cmd="off"/>
<co id="L6" cmd="on"/>
 
</xmlscript>


Configuration

Two Actions are created to start the XML-scripts. “Command”, the path will be entered for the script. In this example, the scripts are stored in the Workspace.

Action "Init scripts" at system startup to initialize the LEDs and "startup script" for evaluating the push-buttons that are pressed.

"Init scripts" located on the system action "init" and "Start Script" is the action on all push-buttons.

Download

Plan und Scripte:
extkeyboardscript.zip

micha68/extkeyboardscript-en.txt · Last modified: 2018/11/12 08:56 (external edit)