<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Name="Konfigurations-Baum" Version="1430" Guid="{640FB32D-5C02-419A-8E04-9904D0003A5E}" Time="1219753803.67">
    <Autostart Name="Autostart">
        <Plugin File="Serial" Identifier="Serial">
            gAIoSwBNAEtLA0sASwBLAIlYAgAAAFxycQBYBgAAAFNlcmlhbHEBSwF0cQIu
        </Plugin>
        <Action>
            EventGhost.NewJumpIf(XmlIdLink(58), 2, True)
        </Action>
    </Autostart>
    <Folder Name="Conrad Relais Board">
        <Folder Name="Relais 1">
            <Macro Name="Relais 1 ON">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, ON", payload=1)')
                </Action>
            </Macro>
            <Macro Name="Relais 1 OFF">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, OFF", payload=1)')
                </Action>
            </Macro>
        </Folder>
        <Folder Name="Relais 2">
            <Macro Name="Relais 2 ON">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, ON", payload=2)')
                </Action>
            </Macro>
            <Macro Name="Relais 2 OFF">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, OFF", payload=2)')
                </Action>
            </Macro>
        </Folder>
        <Folder Name="Relais 3">
            <Macro Name="Relais 3 ON">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, ON", payload=3)')
                </Action>
            </Macro>
            <Macro Name="Relais 3 OFF">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, OFF", payload=3)')
                </Action>
            </Macro>
        </Folder>
        <Folder Name="Relais 4">
            <Macro Name="Relais 4 ON">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, ON", payload=4)')
                </Action>
            </Macro>
            <Macro Name="Relais 4 OFF">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, OFF", payload=4)')
                </Action>
            </Macro>
        </Folder>
        <Folder Name="Relais 5">
            <Macro Name="Relais 5 ON">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, ON", payload=5)')
                </Action>
            </Macro>
            <Macro Name="Relais 5 OFF">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, OFF", payload=5)')
                </Action>
            </Macro>
        </Folder>
        <Folder Name="Relais 6">
            <Macro Name="Relais 6 ON">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, ON", payload=6)')
                </Action>
            </Macro>
            <Macro Name="Relais 6 OFF">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, OFF", payload=6)')
                </Action>
            </Macro>
        </Folder>
        <Folder Name="Relais 7">
            <Macro Name="Relais 7 ON">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, ON", payload=7)')
                </Action>
            </Macro>
            <Macro Name="Relais 7 OFF">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, OFF", payload=7)')
                </Action>
            </Macro>
        </Folder>
        <Folder Name="Relais 8">
            <Macro Name="Relais 8 ON">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, ON", payload=8)')
                </Action>
            </Macro>
            <Macro Name="Relais 8 OFF">
                <Action>
                    EventGhost.PythonScript(u'eg.TriggerEvent("Send to Relais Board, OFF", payload=8)')
                </Action>
            </Macro>
        </Folder>
        <Folder Name="All Relais">
            <Macro Name="All Relais ON">
                <Action>
                    EventGhost.PythonScript(u"eg.globals.serial = eg.plugins.Serial\neg.globals.relais = [0, 0, 0, 0, 0, 0, 0, 0]\ni = 0\nwhile i &lt; 8 :\n    eg.globals.relais[0] = 1\n    i = i + 1\neg.globals.serial.Write('\\\\x' + eg.globals.command + '\\\\x' + eg.globals.boardAddr + '\\xff\\xfd')")
                </Action>
            </Macro>
            <Macro Name="All Relais OFF">
                <Action>
                    EventGhost.PythonScript(u"eg.globals.serial = eg.plugins.Serial\neg.globals.relais = [0, 0, 0, 0, 0, 0, 0, 0]\ni = 0\nwhile i &lt; 8 :\n    eg.globals.relais[0] = 0\n    i = i + 1\neg.globals.serial.Write('\\\\x' + eg.globals.command + '\\\\x' + eg.globals.boardAddr + '\\x00\\x02')")
                </Action>
            </Macro>
        </Folder>
        <Folder Name="Generate Code and Checksum">
            <Macro Name="Relais ON">
                <Event Name="Send to Relais Board, ON" />
                <Action>
                    EventGhost.PythonScript(u'rel = eg.event.payload\nrel = rel - 1\nrelais = eg.globals.relais\nif (rel &lt; 0) or (rel &gt; 7) :\n    print \'Error. Relais has to be between 1 and 8.\'\n    eg.Exit()\ndata = 0\n\n# Generate Data Byte\ni = 0\nwhile i &lt; 8 :\n    if relais[i] == 1 :\n        if rel == i :\n            print "Relais ", i + 1, " has already been switched on."\n            eg.Exit();\n        else :\n            data = data + 2**i\n    else:\n        if rel == i :\n            relais[i] = 1\n            data = data + 2**i\n    i = i + 1\n    \ndata = str(hex(data))[2:]\nif  len(data) &lt; 2 :\n    data = "0" + str(data)\n\n# Generate Checksum\npayload = eg.globals.command + eg.globals.boardAddr + data\na = int(payload[0:2], 16) \nb = int(payload[2:4], 16)\nc = int(payload[4:6], 16)    \nchecksum = a^b^c                             \nhex(checksum)\nchecksum = str(hex(checksum))[2:]\nif  len(checksum) &lt; 2 :\n    checksum = "0" + checksum\n\ndata = \'\\\\x\' + data\nchecksum = \'\\\\x\' + checksum\neg.globals.serial.Write(\'\\\\x\' + eg.globals.command + \'\\\\x\' + eg.globals.boardAddr + data + checksum)\n\n\n\n\n\n\n\n')
                </Action>
            </Macro>
            <Macro Name="Relais OFF">
                <Event Name="Send to Relais Board, OFF" />
                <Action>
                    EventGhost.PythonScript(u'rel = eg.event.payload\nrel = rel - 1\nrelais = eg.globals.relais\nif (rel &lt; 0) or (rel &gt; 7) :\n    print \'Error. Relais has to be between 1 and 8.\'\n    eg.Exit()\ndata = 0\n\n# Generate Data Byte\ni = 0\nwhile i &lt; 8 :\n    if relais[i] == 0 :\n        if rel == i :\n            print "Relais ", i + 1, " has already been switched off."\n            eg.Exit();\n    else:\n        if rel == i :\n            relais[i] = 0\n        else :\n            data = data + 2**i\n    i = i + 1\n    \ndata = str(hex(data))[2:]\nif  len(data) &lt; 2 :\n    data = "0" + str(data)\n\n# Generate Checksum\npayload = eg.globals.command + eg.globals.boardAddr + data\na = int(payload[0:2], 16) \nb = int(payload[2:4], 16)\nc = int(payload[4:6], 16)    \nchecksum = a^b^c                             \nhex(checksum)\nchecksum = str(hex(checksum))[2:]\nif  len(checksum) &lt; 2 :\n    checksum = "0" + checksum\n\ndata = \'\\\\x\' + data\nchecksum = \'\\\\x\' + checksum\neg.globals.serial.Write(\'\\\\x\' + eg.globals.command + \'\\\\x\' + eg.globals.boardAddr + data + checksum)\n\n\n\n\n\n\n\n\n')
                </Action>
            </Macro>
            <Macro Name="Initialize" id="58">
                <Action>
                    EventGhost.PythonScript(u"eg.globals.serial = eg.plugins.Serial\n\n# Control Byte (Default '03'). Use apostrophes.\neg.globals.command = '03'\n\n# Board Address Byte (Default '01') Use apostrophes.\neg.globals.boardAddr = '01'\n\n\n\n# HINT\n# All Relais will be switched off, when starting EG.\n# This is needed because of synchronisation problems with other programs\n# DO NOT use any program to control the card, if EG is running!\n# Conrad Relais Boards can be cascaded (up to 255 cards). However, this script\n# supports just ONE card. (Wouldn't be extremelty difficult to upgrade that, though.)\n\n# Use at your complete own risk!\n# Programmed by mannyk (You can get in contact with me through the forum of EG (http://www.eventghost.org/))\n# Thanks to jinxdone for several valueable hints!\n\neg.globals.relais = [0, 0, 0, 0, 0, 0, 0, 0]\ni = 0\nwhile i &lt; 8 :\n    eg.globals.relais[0] = 0\n    i = i + 1\neg.globals.serial.Write('\\\\x' + eg.globals.command + '\\\\x' + eg.globals.boardAddr + '\\x00\\x02');")
                </Action>
            </Macro>
        </Folder>
    </Folder>
</EventGhost>
