/// <summary> /// Initializes the device tags. /// </summary> public override void InitDeviceTags() { if (opcDeviceConfig == null) { return; } foreach (SubscriptionConfig subscriptionConfig in opcDeviceConfig.Subscriptions) { TagGroup tagGroup = new TagGroup(subscriptionConfig.DisplayName); foreach (ItemConfig itemConfig in subscriptionConfig.Items) { DeviceTag deviceTag = tagGroup.AddTag(itemConfig.TagCode, itemConfig.DisplayName); deviceTag.Aux = new DeviceTagMeta(); itemConfig.Tag = deviceTag; if (itemConfig.IsString) { deviceTag.DataLen = DriverUtils.GetTagDataLength(itemConfig.DataLength); deviceTag.DataType = TagDataType.Unicode; deviceTag.Format = TagFormat.String; } else if (itemConfig.IsArray) { deviceTag.DataLen = itemConfig.DataLength; } } DeviceTags.AddGroup(tagGroup); } }
/// <summary> /// Initializes the device tags. /// </summary> public override void InitDeviceTags() { foreach (CnlPrototypeGroup group in CnlPrototypeFactory.GetCnlPrototypeGroups()) { DeviceTags.AddGroup(group.ToTagGroup()); } }
/// <summary> /// Initializes the device tags. /// </summary> public override void InitDeviceTags() { TagGroup tagGroup = new TagGroup(); tagGroup.AddTag(TagCode.Mail, TagName.Mail).Format = TagFormat.IntNumber; tagGroup.AddTag(TagCode.MailAttach, TagName.MailAttach).Format = TagFormat.IntNumber; DeviceTags.AddGroup(tagGroup); }
/// <summary> /// Initializes the device tags. /// </summary> public override void InitDeviceTags() { TagGroup tagGroup = new TagGroup("Inputs"); tagGroup.AddTag("Sin", "Sine"); tagGroup.AddTag("Sqr", "Square").Format = TagFormat.OffOn; tagGroup.AddTag("Tr", "Triangle"); DeviceTags.AddGroup(tagGroup); tagGroup = new TagGroup("Outputs"); tagGroup.AddTag("DO", "Relay State").Format = TagFormat.OffOn; tagGroup.AddTag("AO", "Analog Output"); DeviceTags.AddGroup(tagGroup); }
/// <summary> /// Initializes the device tags. /// </summary> public override void InitDeviceTags() { DeviceTemplate deviceTemplate = GetDeviceTemplate(); if (deviceTemplate == null) { return; } // create device model deviceModel = CreateDeviceModel(); deviceModel.Addr = (byte)NumAddress; // add model elements and device tags foreach (ElemGroupConfig elemGroupConfig in deviceTemplate.ElemGroups) { bool groupActive = elemGroupConfig.Active; bool groupCommands = groupActive && elemGroupConfig.ReadOnlyEnabled; ElemGroup elemGroup = null; TagGroup tagGroup = new TagGroup(elemGroupConfig.Name) { Hidden = !groupActive }; int elemIndex = 0; if (groupActive) { elemGroup = deviceModel.CreateElemGroup(elemGroupConfig.DataBlock); elemGroup.Name = elemGroupConfig.Name; elemGroup.Address = (ushort)elemGroupConfig.Address; elemGroup.StartTagIdx = DeviceTags.Count; } foreach (ElemConfig elemConfig in elemGroupConfig.Elems) { // add model element if (groupActive) { Elem elem = elemGroup.CreateElem(); elem.Name = elemConfig.Name; elem.ElemType = elemConfig.ElemType; elem.ByteOrder = ModbusUtils.ParseByteOrder(elemConfig.ByteOrder) ?? deviceTemplate.Options.GetDefaultByteOrder(ModbusUtils.GetDataLength(elemConfig.ElemType)); elemGroup.Elems.Add(elem); } // add model command if (groupCommands && !elemConfig.ReadOnly && !string.IsNullOrEmpty(elemConfig.TagCode)) { deviceModel.Cmds.Add( CreateModbusCmd(deviceTemplate.Options, elemGroupConfig, elemConfig, elemIndex)); } // add device tag tagGroup.AddTag(elemConfig.TagCode, elemConfig.Name).SetFormat(GetTagFormat(elemConfig)); elemIndex++; } if (groupActive) { elemGroup.InitReqPDU(); elemGroup.InitReqADU(deviceModel.Addr, transMode); deviceModel.ElemGroups.Add(elemGroup); } DeviceTags.AddGroup(tagGroup); } // add model commands foreach (CmdConfig cmdConfig in deviceTemplate.Cmds) { deviceModel.Cmds.Add(CreateModbusCmd(deviceTemplate.Options, cmdConfig)); } deviceModel.InitCmdMap(); CanSendCommands = deviceModel.Cmds.Count > 0; InitModbusPoll(); }
/// <summary> /// Initializes the device tags. /// </summary> public override void InitDeviceTags() { DeviceTags.AddGroup(CnlPrototypeFactory.GetCnlPrototypeGroup().ToTagGroup()); }
/// <summary> /// Writes an item value to the OPC server. /// </summary> private bool WriteItemValue(CommandConfig commandConfig, double cmdVal, string cmdData) { // get data type string dataTypeName = commandConfig.DataTypeName; Type itemDataType = null; object itemVal; if (string.IsNullOrEmpty(dataTypeName)) { if (DeviceTags.TryGetTag(commandConfig.CmdCode, out DeviceTag deviceTag) && deviceTag.Aux is DeviceTagMeta tagMeta) { itemDataType = tagMeta.ActualDataType; } } else { itemDataType = Type.GetType(dataTypeName, false, true); } if (itemDataType == null) { throw new ScadaException(Locale.IsRussian ? "Не удалось получить тип данных {0}" : "Unable to get data type {0}", dataTypeName); } if (itemDataType.IsArray) { throw new ScadaException(Locale.IsRussian ? "Тип данных {0} не поддерживается" : "Data type {0} not supported", dataTypeName); } // define command value try { if (itemDataType == typeof(string)) { itemVal = cmdData; } else if (itemDataType == typeof(DateTime)) { itemVal = DateTime.FromOADate(cmdVal); } else { itemVal = Convert.ChangeType(cmdVal, itemDataType); } } catch { throw new ScadaException(Locale.IsRussian ? "Не удалось привести значение к типу {0}" : "Unable to convert value to the type {0}", itemDataType.FullName); } // write value Log.WriteLine(Locale.IsRussian ? "Отправка значения OPC-серверу: {0} = {1}" : "Send value to the OPC server: {0} = {1}", commandConfig.DisplayName, itemVal); WriteValue valueToWrite = new WriteValue { NodeId = commandConfig.NodeID, AttributeId = Attributes.Value, Value = new DataValue(new Variant(itemVal)) }; opcSession.Write(null, new WriteValueCollection { valueToWrite }, out StatusCodeCollection results, out _); if (StatusCode.IsGood(results[0])) { Log.WriteLine(CommPhrases.ResponseOK); return(true); } else { Log.WriteLine(CommPhrases.ResponseError); return(false); } }