# coding=utf-8
import sys
import time
import IRControl

if __name__ == "__main__":
    result = IRControl.IsAppRunning("C:\\Python27\\Tools\\RedRatHub-V4.28\\RedRatHubCmd.exe")
    if result is True:
        print "红老鼠服务程序已打开"
    else:
        print "红老鼠服务程序未打开"
        result = IRControl.StartApp("C:\\Python27\\Tools\\RedRatHub-V4.28\\RedRatHubCmd.exe", "C:\\Python27\\Tools\\RedRatHub-V4.28\\DeviceDB.xml", 40000)
        if result:
            print "红老鼠服务程序打开成功"
        else:
            print "红老鼠服务程序打开失败"

    time.sleep(1)
    if result:
        # 连接设备;
        result = IRControl.ConnectDevice("127.0.0.1", 40000)
        if result is False:
            print "连接红老鼠TCP服务端失败"
        else:
            print "连接红老鼠TCP服务端成功"

    if result:
        # 获取设备列表，以逗号分隔;
        devices = IRControl.getDeviceNames()
        print devices.split(';')

        # 加载指定目录的信号集XML文件;
        result = IRControl.loadSignalDataSet(r"D:\SAT\resource\RCU\product\ARTEL_WZ_RC311_2841.xml")
        if result:
            print "加载指定信号数据集成功"
        else:
            print "加载指定信号数据集失败"

        # 获取设备列表，以逗号分隔;
        signals = IRControl.getSignalsName("")
        print signals.split('\n')

        # 发送单个信号;
        result = IRControl.sendSignal("HOME", 1, 1000)
        if result:
            print "发送单个信号成功"
        else:
            print "发送单个信号失败"

        # 发送多个信号;
        result = IRControl.sendSignals("HOME;right;right;down;down;up;HOME", 100)
        if result:
            print "发送多个信号成功"
        else:
            print "发送多个信号失败"

        # 发送重复信号;
        result = IRControl.sendRepeatsSignal("right", 3)
        if result:
            print "发送重复信号成功"
        else:
            print "发送重复信号失败"

    # 结束任务，断开连接;
    IRControl.DisconnectDevice()



