public override void InitNodeTemplates(INodeTemplateFactory factory) { factory.CreateInterfaceType(DeviceInterface, "MODBUS.DEVICE", "", 250, 250, true); factory.CreateInterfaceType(AttributeInterface, "MODBUS.ATTRIBUTE", "", ushort.MaxValue, byte.MaxValue, false); factory.CreateNodeTemplate(DeviceTemplate, "MODBUS.DEVICE.NAME", "MODBUS.DEVICE.DESCRIPTION", "modbus-device", DeviceInterface, AttributeInterface, false, true, false, true, false, NodeDataType.NoAttribute, 250, false); var devicePropGuid = new Guid("7765b031-ba80-485e-a136-7d6ed4dc7918"); factory.CreatePropertyTemplate(devicePropGuid, "MODBUS.DEVICE.ID", "", "modbus-device-id", PropertyTemplateType.Integer, DeviceTemplate, "MODBUS.CATEGORY.DEVICE", true, false, "", 0, 0, 1); factory.CreatePropertyConstraint(new Guid("7765b031-ba80-485e-a136-7d6ed4dc79FF"), "MODBUS.CONSTRAINT.UNIQUE_ADDRESS.NAME", "MODBUS.CONSTRAINT.UNIQUE_ADDRESS.NAME", PropertyConstraint.Unique, PropertyConstraintLevel.Error, devicePropGuid); var pollGuid = new Guid("01021bd7-d4d1-4bee-8cc6-7dfe5e47feb4"); factory.CreatePropertyTemplate(pollGuid, "MODBUS.PROPERTY.POLL_INTERVAL.NAME", "MODBUS.PROPERTY.POLL_INTERVAL.DESCRIPTION", "modbus-poll-interval", PropertyTemplateType.Integer, DeviceTemplate, "MODBUS.CATEGORY.DEVICE", true, false, PropertyHelper.CreateRangeMetaString(1, 65535), 5000, 1, 1); var pollGuidConstraint = new Guid("2e2d2e72-f0ee-4fa5-902d-3cdba4db7949"); factory.CreatePropertyConstraint(pollGuidConstraint, "MODBUS.CONSTRAINT.POLL_INTERVAL_ON_MASTER.NAME", "MODBUS.CONSTRAINT.POLL_INTERVAL_ON_MASTER.DESCRIPTION", PropertyConstraint.Visible, PropertyConstraintLevel.None, pollGuid); factory.CreatePropertyConstraintData(new Guid("d4f060da-583d-4b0c-a75b-f12a3526f2f6"), 1, 0, pollGuidConstraint, "modbus-type", PropertyConstraintConditionType.ParentCondition); factory.CreatePropertyConstraintData(new Guid("2faa4f9b-ca1d-491f-aea1-b013f6570331"), 1, 0, pollGuidConstraint, ":MODBUS-MASTER", PropertyConstraintConditionType.ParentCondition); factory.CreateNodeTemplate(Register2ByteGuid, "MODBUS.ATTRIBUTE.INTEGER.POS2BYTE.NAME", "MODBUS.ATTRIBUTE.INTEGER.POS2BYTE.DESCRIPTION", "modbus-+2byte", AttributeInterface, GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Value), false, true, false, true, false, NodeDataType.Integer, ushort.MaxValue, false); CreatePropertiesForModbusValue(Register2ByteGuid, factory, true, 1); factory.CreateNodeTemplate(Register2ByteUnsignedGuid, "MODBUS.ATTRIBUTE.INTEGER.NEG2BYTE.NAME", "MODBUS.ATTRIBUTE.INTEGER.NEG2BYTE.DESCRIPTION", "modbus-2byte", AttributeInterface, GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Value), false, true, false, true, false, NodeDataType.Integer, ushort.MaxValue, false); CreatePropertiesForModbusValue(Register2ByteUnsignedGuid, factory, true, 1); factory.CreateNodeTemplate(Register4ByteGuid, "MODBUS.ATTRIBUTE.INTEGER.POS4BYTE.NAME", "MODBUS.ATTRIBUTE.INTEGER.POS4BYTE.DESCRIPTION", "modbus-+4byte", AttributeInterface, GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Value), false, true, false, true, false, NodeDataType.Integer, ushort.MaxValue, false); CreatePropertiesForModbusValue(Register4ByteGuid, factory, true, 2); factory.CreateNodeTemplate(Register4ByteUnsignedGuid, "MODBUS.ATTRIBUTE.INTEGER.NEG4BYTE.NAME", "MODBUS.ATTRIBUTE.INTEGER.NEG4BYTE.DESCRIPTION", "modbus-4byte", AttributeInterface, GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Value), false, true, false, true, false, NodeDataType.Integer, short.MaxValue, false); CreatePropertiesForModbusValue(Register4ByteUnsignedGuid, factory, true, 2); factory.CreateNodeTemplate(Register8ByteGuid, "MODBUS.ATTRIBUTE.INTEGER.POS8BYTE.NAME", "MODBUS.ATTRIBUTE.INTEGER.POS8BYTE.DESCRIPTION", "modbus-+8byte", AttributeInterface, GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Value), false, true, false, true, false, NodeDataType.Integer, ushort.MaxValue, false); CreatePropertiesForModbusValue(Register8ByteGuid, factory, true, 4); factory.CreateNodeTemplate(Register8ByteUnsignedGuid, "MODBUS.ATTRIBUTE.INTEGER.NEG8BYTE.NAME", "MODBUS.ATTRIBUTE.INTEGER.NEG8BYTE.DESCRIPTION", "modbus-8byte", AttributeInterface, GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Value), false, true, false, true, false, NodeDataType.Integer, ushort.MaxValue, false); CreatePropertiesForModbusValue(Register8ByteUnsignedGuid, factory, true, 4); factory.CreateNodeTemplate(Register4ByteFloat, "MODBUS.ATTRIBUTE.FLOAT.4BYTE.NAME", "MODBUS.ATTRIBUTE.FLOAT.4BYTE.DESCRIPTION", "modbus-4float", AttributeInterface, GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Value), false, true, false, true, false, NodeDataType.Double, ushort.MaxValue, false); CreatePropertiesForModbusValue(Register4ByteFloat, factory, true, 2); factory.CreateNodeTemplate(Register8ByteFloat, "MODBUS.ATTRIBUTE.FLOAT.8BYTE.NAME", "MODBUS.ATTRIBUTE.FLOAT.8BYTE.DESCRIPTION", "modbus-8float", AttributeInterface, GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Value), false, true, false, true, false, NodeDataType.Double, ushort.MaxValue, false); CreatePropertiesForModbusValue(Register8ByteFloat, factory, true, 4); factory.CreateNodeTemplate(CoilsYesNo, "MODBUS.ATTRIBUTE.BINARY.NAME", "MODBUS.ATTRIBUTE.BINARY.DESCRIPTION", "modbus-binary", AttributeInterface, GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Value), false, true, false, true, false, NodeDataType.Boolean, ushort.MaxValue, false); CreatePropertiesForModbusValue(CoilsYesNo, factory, false, 1); InitTemplates(factory); }
private void CreatePropertiesForModbusValue(Guid nodeGuid, INodeTemplateFactory factory, bool isByteRegister, int registerLength) { var propGuid = GenerateNewGuid(nodeGuid, 1); factory.CreatePropertyTemplate(propGuid, "MODBUS.PROPERTY.REGISTER", "", "modbus-register", PropertyTemplateType.Range, nodeGuid, "COMMON.CATEGORY.ADDRESS", true, false, PropertyHelper.CreateRangeMetaString(0, short.MaxValue - 1), 0, 0, 0); var propConstraint = GenerateNewGuid(nodeGuid, 10); factory.CreatePropertyConstraint(propConstraint, "MODBUS.CONSTRAINT.REGISTER_ADDRESS.NAME", "MODBUS.CONSTRAINT.REGISTER_ADDRESS.DESCRIPTION", PropertyConstraint.UniqueOnCondition, PropertyConstraintLevel.Warn, propGuid); var modbusTablePropGuid = GenerateNewGuid(nodeGuid, 2); var modbusRegLengthPropGuid = GenerateNewGuid(nodeGuid, 6); factory.CreatePropertyConstraintData(GenerateNewGuid(nodeGuid, 20), 1, -1, propConstraint, "modbus-table", PropertyConstraintConditionType.Unique); factory.CreatePropertyConstraintData(GenerateNewGuid(nodeGuid, 30), 1, -1, propConstraint, "modbus-register-length", PropertyConstraintConditionType.UniqueRange); if (isByteRegister) { factory.CreatePropertyTemplate(modbusTablePropGuid, "MODBUS.PROPERTY.TABLE", "", "modbus-table", PropertyTemplateType.Enum, nodeGuid, "COMMON.CATEGORY.ADDRESS", true, false, PropertyHelper.CreateEnumMetaString(typeof(ModBusTable), 0, 1), 0, 0, 0); factory.ChangeDefaultVisuTemplate(nodeGuid, VisuMobileObjectTemplateTypes.NumberBox); if (registerLength == 2) { factory.CreatePropertyTemplate(GenerateNewGuid(nodeGuid, 3), "MODBUS.PROPERTY.BYTEORDER", "", "modbus-byte-order", PropertyTemplateType.Enum, nodeGuid, "COMMON.CATEGORY.ADDRESS", true, false, PropertyHelper.CreateEnumMetaString(typeof(ModBus4ByteOrder)), 0, 0, 0); } else if (registerLength == 4) { factory.CreatePropertyTemplate(GenerateNewGuid(nodeGuid, 3), "MODBUS.PROPERTY.BYTEORDER", "", "modbus-byte-order", PropertyTemplateType.Enum, nodeGuid, "COMMON.CATEGORY.ADDRESS", true, false, PropertyHelper.CreateEnumMetaString(typeof(ModBus8ByteOrder)), 0, 0, 0); } factory.CreatePropertyTemplate(GenerateNewGuid(nodeGuid, 4), "COMMON.FACTOR.NAME", "COMMON.FACTOR.DESCRIPTION", "factor", PropertyTemplateType.Numeric, nodeGuid, "COMMON.CATEGORY.TRANSFORM", true, false, "", 1, 2, 1); factory.CreatePropertyTemplate(GenerateNewGuid(nodeGuid, 5), "COMMON.OFFSET.NAME", "COMMON.OFFSET.DESCRIPTION", "offset", PropertyTemplateType.Numeric, nodeGuid, "COMMON.CATEGORY.TRANSFORM", true, false, "", 0, 2, 2); factory.CreatePropertyTemplate(modbusRegLengthPropGuid, "MODBUS.REGISTER.LENGTH", "MODBUS.REGISTER.LENGTH", "modbus-register-length", PropertyTemplateType.Numeric, nodeGuid, "COMMON.CATEGORY.TRANSFORM", false, true, "", registerLength, 2, 2); } else { factory.ChangeDefaultVisuTemplate(nodeGuid, VisuMobileObjectTemplateTypes.ToggleButton); factory.CreatePropertyTemplate(modbusTablePropGuid, "MODBUS.PROPERTY.TABLE", "", "modbus-table", PropertyTemplateType.Enum, nodeGuid, "COMMON.CATEGORY.ADDRESS", true, false, PropertyHelper.CreateEnumMetaString(typeof(ModBusTable), 2, 3), 2, 0, 0); factory.CreatePropertyTemplate(modbusRegLengthPropGuid, "MODBUS.REGISTER.LENGTH", "MODBUS.REGISTER.LENGTH", "modbus-register-length", PropertyTemplateType.Numeric, nodeGuid, "COMMON.CATEGORY.TRANSFORM", false, true, "", 1, 2, 2); } }