Exemplo n.º 1
0
        /// <summary>
        /// Updates the device parameters in the INI file.  It is necessary to restart the thread for the new values to take effect.
        /// </summary>
        /// <param name="refIdStr">The device reference identifier (as string) for HomeSeer.</param>
        /// <param name="ipAddress">The ip address.</param>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns><c>true</c> if the update was successful, <c>false</c> otherwise.</returns>
        public bool UpdateDevice(string refIdStr, string ipAddress, string username, string password)
        {
            int refId;

            if (!Int32.TryParse(refIdStr, out refId))
            {
                return(false);
            }

            Scheduler.Classes.DeviceClass hsDevice = (Scheduler.Classes.DeviceClass)hs.GetDeviceByRef(refId);
            if (hsDevice == null)
            {
                return(false);
            }

            // save the settings
            hs.SaveINISetting("Camera" + refIdStr, "IpAddress", ipAddress, INI_File);
            hs.SaveINISetting("Camera" + refIdStr, "Username", username, INI_File);
            if (password != "")
            {
                hs.SaveINISetting("Camera" + refIdStr, "Password", password, INI_File);
            }

            HikAlarmThreadManager.DeleteDevice(refId);
            HikAlarmThreadManager.AddDevice(this, refId, ipAddress, username, password);

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a device from the configuration information.  Save the information in the INI file.
        /// </summary>
        /// <param name="name">The name for the device.</param>
        /// <param name="ipAddress">The ip address for the device.</param>
        /// <param name="username">The username for the device.</param>
        /// <param name="password">The password for the device.</param>
        /// <returns>The device reference identifier from HomeSeer.</returns>
        public int CreateDeviceFromConfig(string name, string ipAddress, string username, string password)
        {
            Console.WriteLine("Name:      {0}", name);
            Console.WriteLine("IpAddress: {0}", ipAddress);
            Console.WriteLine("Username:  {0}", username);
            Console.WriteLine("Password:  {0}", password);

            // create the device in HomeSeer
            int refId;

            Scheduler.Classes.DeviceClass hsDevice = CreateDevice(out refId, name);
            if (hsDevice == null)
            {
                return(-1);
            }

            // save the settings
            hs.SaveINISetting("Camera" + refId, "IpAddress", ipAddress, INI_File);
            hs.SaveINISetting("Camera" + refId, "Username", username, INI_File);
            hs.SaveINISetting("Camera" + refId, "Password", password, INI_File);

            // start a new thread
            HikAlarmThreadManager.AddDevice(this, refId, ipAddress, username, password);

            return(refId);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialize the plugin and associated hardware/software, start any threads
        /// </summary>
        /// <param name="port">The COM port for the plugin if required.</param>
        /// <returns>Warning message or empty for success.</returns>
        public override string InitIO(string port)
        {
            // initialize everything here, return a blank string only if successful, or an error message
            try
            {
                Scheduler.Classes.clsDeviceEnumeration EN = (Scheduler.Classes.clsDeviceEnumeration)hs.GetDeviceEnumerator();
                if (EN == null)
                {
                    throw new Exception(IFACE_NAME + " failed to get a device enumerator from HomeSeer.");
                }
                do
                {
                    Scheduler.Classes.DeviceClass dv = EN.GetNext();
                    if ((dv != null) &&
                        (dv.get_Interface(hs) != null) &&
                        (dv.get_Interface(hs).Trim() == IFACE_NAME))
                    {
                        //Console.WriteLine("Found device: refId = {0}", dv.get_Ref(hs));
                        int    refId     = dv.get_Ref(hs);
                        string ipAddress = hs.GetINISetting("Camera" + refId, "IpAddress", "", INI_File);
                        string username  = hs.GetINISetting("Camera" + refId, "Username", "", INI_File);
                        string password  = hs.GetINISetting("Camera" + refId, "Password", "", INI_File);
                        Console.WriteLine("Camera: RefId: {0}, IpAddress: {1}, Username: {2}, Password: {3}", refId, ipAddress, username, password);

                        HikAlarmThreadManager.AddDevice(this, refId, ipAddress, username, password);
                    }
                } while (!EN.Finished);
            }
            catch (Exception ex)
            {
                hs.WriteLog(IFACE_NAME + " Error", "Exception in Find_Create_Devices/Enumerator: " + ex.Message);
            }

            // Create and register the web pages - only need one for configuration
            configPage = new HikAlarmConfig(this);
            RegisterWebPage(configPage.Name);

            return("");
        }