Beispiel #1
0
        private List <SiidDevice> GetDevices(InstanceHolder Instance)
        {
            List <SiidDevice> AssociatedDevices = new List <SiidDevice>();

            Scheduler.Classes.clsDeviceEnumeration DevNum = (Scheduler.Classes.clsDeviceEnumeration)Instance.host.GetDeviceEnumerator();
            var Dev = DevNum.GetNext();

            while (Dev != null)
            {
                if ((Dev.get_Interface(Instance.host).ToString() == Util.IFACE_NAME.ToString()) && (Dev.get_InterfaceInstance(Instance.host) == Instance.name))
                {
                    AssociatedDevices.Add(new SiidDevice(Instance, Dev));
                }

                Dev = DevNum.GetNext();
            }

            return(AssociatedDevices);
        }
Beispiel #2
0
 public HomeSeerDevice(SiidDevice SiidDev, InstanceHolder instance)
 {
     Instance = instance;
     GenericDeviceStuff(SiidDev);
 }
Beispiel #3
0
        public static void AddInstance(string InstanceName)
        {
            if (AllInstances.ContainsKey(InstanceName))
            {
                return;
            }
            else
            {
                HSPI plugIn = new HSPI();

                string sIp = "127.0.0.1";
                // plugIn.OurInstanceFriendlyName = InstanceName;
                HSCF.Communication.ScsServices.Client.IScsServiceClient <IHSApplication>  client         = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(sIp, 10400), plugIn);
                HSCF.Communication.ScsServices.Client.IScsServiceClient <IAppCallbackAPI> clientCallback = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(new ScsTcpEndPoint(sIp, 10400), plugIn);
                HomeSeerAPI.IHSApplication host = null;
                IAppCallbackAPI            callback;


                int Attempts = 1;
TryAgain:

                try
                {
                    client.Connect();
                    clientCallback.Connect();

                    double APIVersion = 0;

                    try
                    {
                        host       = client.ServiceProxy;
                        APIVersion = host.APIVersion;
                        // will cause an error if not really connected
                        Console.WriteLine("Host API Version: " + APIVersion.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error getting API version from host object: " + ex.Message + "->" + ex.StackTrace);
                        //Return
                    }

                    try
                    {
                        callback   = clientCallback.ServiceProxy;
                        APIVersion = callback.APIVersion;
                        // will cause an error if not really connected
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error getting API version from callback object: " + ex.Message + "->" + ex.StackTrace);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Cannot connect attempt " + Attempts.ToString() + ": " + ex.Message);
                    if (ex.Message.ToLower().Contains("timeout occurred."))
                    {
                        Attempts += 1;
                        if (Attempts < 6)
                        {
                            goto TryAgain;
                        }
                    }

                    if (client != null)
                    {
                        client.Dispose();
                        client = null;
                    }
                    if (clientCallback != null)
                    {
                        clientCallback.Dispose();
                        clientCallback = null;
                    }
                    wait(4);
                    return;
                }

                try
                {
                    AllInstances[InstanceName] = new InstanceHolder(plugIn, client, callback, host, InstanceName);
                    host.Connect(Util.IFACE_NAME, InstanceName);
                    Console.WriteLine("Connected, waiting to be initialized...");

                    //  plugIn.OurInstanceFriendlyName = InstanceName;

                    // create the user object that is the real plugIn, accessed from the plugInAPI wrapper
                    //  AllInstances[InstanceFriendlyName].callback = callback;
                    //  Util.hs = host;
                    //   plugIn.OurInstanceFriendlyName = Util.Instance;
                    // connect to HS so it can register a callback to us
                    //   host.Connect(Util.IFACE_NAME, Util.Instance);
                    int Count = 0;
                    do
                    {
                        System.Threading.Thread.Sleep(1000);

                        /*     Count = (Count + 1) % (60*5);//save every 5 minutes, not every minute
                         * if (Count == 0)
                         * {
                         *    foreach (var Instance in AllInstances)
                         *    {
                         *        Instance.Value.hspi.Log("Saving devices for Instance "+Instance.Key, 0);
                         *        Instance.Value.host.SaveEventsDevices();  //THis function doesn't save plugin created devices, so not necessary to call
                         *    }
                         * }*/
                    } while (client.CommunicationState == HSCF.Communication.Scs.Communication.CommunicationStates.Connected & !HSPI.bShutDown);
                    Console.WriteLine("Connection lost, exiting");

                    // disconnect from server for good here
                    //
                    // clientCallback.Disconnect();
                    //wait(2);
                    if (AllInstances.Count == 0)
                    {
                        client.Disconnect();
                        wait(2);
                        System.Environment.Exit(0);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Cannot connect(2): " + ex.Message);
                    wait(2);
                    System.Environment.Exit(0);
                    return;
                }
            }
        }
Beispiel #4
0
        public SIIDDevice(SiidDevice SiidDev, InstanceHolder instance) : base(SiidDev, instance)
        {
            Instance = instance;


            Scheduler.Classes.DeviceClass Device = SiidDev.Device;
            var EDO = SiidDev.Extra;

            System.Collections.Specialized.NameValueCollection parts = HttpUtility.ParseQueryString(EDO.GetNamed("SSIDKey").ToString());
            //Need to grab the key order from somewhere
            string[] Orderlist = null;
            switch (parts["Type"])
            {
            case ("Modbus Gateway"): {
                Orderlist = ModbusMaster.Attributes;
                break;
            }

            case ("Modbus Device"):
            {
                Orderlist = ModbusDevice.Attributes;
                break;
            }

            case ("BACnet Device"):
            case ("BACnet Object"):
            {
                //Need to export everything that we would need in order to import.  All of bacnetNodeData, essentially.
                //To this end, maybe it would be easiest to also store device-level stuff in object nodes - i.e. device IP address



                Orderlist = BACnetObject.Attributes;


                System.Collections.Specialized.NameValueCollection bacnetNodeData = BACnetDevices.ParseJsonString(parts["BACnetNodeData"]);         // HttpUtility.ParseQueryString(parts["BACnetNodeData"]);



                foreach (var Ent in Orderlist)
                {
                    listOfAttributes.Add(Ent);



                    switch (Ent)
                    {
                    case "Type":
                        Values[Ent] = parts[Ent];
                        break;


                    case "NetworkIPAddress":
                        Values[Ent] = bacnetNodeData["ip_address"];
                        break;

                    case "DeviceIPAddress":
                        Values[Ent] = bacnetNodeData["device_ip_address"];
                        break;

                    case "DeviceUDPPort":
                        Values[Ent] = bacnetNodeData["device_udp_port"];
                        break;


                    case "DeviceInstance":
                        Values[Ent] = bacnetNodeData["device_instance"];
                        break;


                    case "ObjectType":
                        Values[Ent] = bacnetNodeData["object_type_string"];
                        break;


                    case "ObjectInstance":
                        Values[Ent] = bacnetNodeData["object_instance"];
                        break;


                    case "ObjectName":
                        Values[Ent] = bacnetNodeData["object_name"];
                        break;


                    case "PollInterval":
                        Values[Ent] = bacnetNodeData["polling_interval"];
                        break;


                    case "RawValue":
                    case "ProcessedValue":
                        Values[Ent] = parts[Ent];
                        break;
                    }
                }


                return;
                //Orderlist = BACnetDevice.Attributes;
                //break;
            }

            case ("Scratchpad"):
            {
                Orderlist = ScratchpadDevice.Attributes;
                break;
            }
            }

            foreach (var Ent in Orderlist)
            {
                Values[Ent] = parts[Ent];
                listOfAttributes.Add(Ent);
            }
        }