예제 #1
0
        /// <summary>
        /// Creates the HS device.
        /// </summary>
        /// <param name="parent">The data for parent of device.</param>
        /// <param name="rootDeviceData">The root device data.</param>
        /// <param name="deviceData">The device data.</param>
        /// <returns>New Device</returns>
        private DeviceClass CreateDevice([AllowNull] DeviceClass parent, [AllowNull] RootDeviceData rootDeviceData, DeviceDataBase deviceData)
        {
            if (rootDeviceData != null)
            {
                LogDebug(Invariant($"Creating {deviceData.Name} under {rootDeviceData.Name}"));
            }
            else
            {
                LogDebug(Invariant($"Creating Root {deviceData.Name}"));
            }

            DeviceClass device = null;
            int         refId  = HS.NewDeviceRef(rootDeviceData != null ? Invariant($"{rootDeviceData.Name} {deviceData.Name}") : deviceData.Name);

            if (refId > 0)
            {
                device = (DeviceClass)HS.GetDeviceByRef(refId);
                string address = rootDeviceData != null?CreateChildAddress(rootDeviceData.Name, deviceData.Name) : deviceData.Name;

                device.set_Address(HS, address);
                device.set_Device_Type_String(HS, deviceData.HSDeviceTypeString);
                var deviceType = new DeviceTypeInfo_m.DeviceTypeInfo();
                deviceType.Device_API  = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In;
                deviceType.Device_Type = deviceData.HSDeviceType;

                device.set_DeviceType_Set(HS, deviceType);
                device.set_Interface(HS, Name);
                device.set_InterfaceInstance(HS, string.Empty);
                device.set_Last_Change(HS, DateTime.Now);
                device.set_Location(HS, Name);
                var pairs = deviceData.StatusPairs;
                foreach (var pair in pairs)
                {
                    HS.DeviceVSP_AddPair(refId, pair);
                }

                var gPairs = deviceData.GraphicsPairs;
                foreach (var gpair in gPairs)
                {
                    HS.DeviceVGP_AddPair(refId, gpair);
                }

                device.MISC_Set(HS, Enums.dvMISC.STATUS_ONLY);
                device.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES);
                device.MISC_Clear(HS, Enums.dvMISC.AUTO_VOICE_COMMAND);
                device.MISC_Clear(HS, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE);
                device.set_Status_Support(HS, false);

                if (parent != null)
                {
                    parent.set_Relationship(HS, Enums.eRelationship.Parent_Root);
                    device.set_Relationship(HS, Enums.eRelationship.Child);
                    device.AssociatedDevice_Add(HS, parent.get_Ref(HS));
                    parent.AssociatedDevice_Add(HS, device.get_Ref(HS));
                }
                deviceData.SetInitialData(HS, device);
            }

            return(device);
        }
예제 #2
0
        private string BuildTab(RootDeviceData root)
        {
            StringBuilder stb    = new StringBuilder();
            string        idName = NameToId(root.Name);

            stb.Append(@"<br>");
            stb.Append(PageBuilderAndMenu.clsPageBuilder.FormStart(Invariant($"ftm{idName}"), Invariant($"Id{idName}"), "Post"));

            stb.Append(DivStart(idName + "div", string.Empty));
            stb.Append(@"<table class='full_width_table'");
            stb.Append("<tr height='5'><td colspan=2></td></tr>");
            stb.Append("<tr><td colspan=2> </td></tr>");
            stb.Append("<tr><td colspan=2><strong>Select devices to be created</strong><td></tr>");
            stb.Append("<tr><td colspan=2> </td></tr>");

            foreach (var childDeviceDefinition in root.Children)
            {
                stb.Append(Invariant($"<tr><td colspan=2>{FormCheckBox(NameToId(root, childDeviceDefinition), childDeviceDefinition.Name, pluginConfig.GetDeviceEnabled(root, childDeviceDefinition))}</td></tr>"));
            }
            stb.Append(@" </table>");
            stb.Append(DivEnd());
            stb.Append(PageBuilderAndMenu.clsPageBuilder.FormEnd());

            return(stb.ToString());
        }