Пример #1
0
        //Добавить сигнал приемника
        public ProviderSignal AddSignal(string signalInf, string code, DataType dataType)
        {
            if (_signalsCode.ContainsKey(code))
            {
                return(_signalsCode[code]);
            }
            var item = new OpcItem(signalInf, code, dataType, this);

            _signals.Add(item.Code, item);
            _signalsCode.Add(code, item);
            item.Tag           = GetOpcItemTag(item.Inf);
            item.ClientHandler = _signals.Count;
            if (!_items.ContainsKey(item.Tag))
            {
                _items.Add(item.Tag, item);
            }
            return(item);
        }
Пример #2
0
        //Добавить сигнал приемника, задав только тэг (для тестовой записи в настройках), сразу же передается значение как строка
        public ProviderSignal AddSignalByTag(string tag, DataType dataType, string v)
        {
            if (_signalsCode.ContainsKey(tag))
            {
                return(_signalsCode[tag]);
            }
            var item = new OpcItem("", tag, dataType, this);

            _signals.Add(item.Code, item);
            _signalsCode.Add(tag, item);
            item.Tag           = tag;
            item.ClientHandler = _signals.Count;
            item.Value         = new SingleValue(new Moment(dataType, v));
            if (!_items.ContainsKey(item.Tag))
            {
                _items.Add(item.Tag, item);
            }
            return(item);
        }
Пример #3
0
 //Добавление итемов на сервер
 private bool TryPrepare()
 {
     if (!IsConnected && !Connect())
     {
         return(false);
     }
     try
     {
         if (_group == null)
         {
             AddGroup("Gr" + (_server.OPCGroups.Count + 1));
         }
         int n    = _items.Count;
         var list = new OpcItem[n + 1];
         int i    = 1;
         foreach (var item in _items.Values)
         {
             list[i++] = item;
         }
         if (n == 0)
         {
             _itemsList = null;
         }
         else
         {
             Array clientH   = Array.CreateInstance(typeof(Int32), n + 1);
             var   itemArr   = Array.CreateInstance(typeof(string), n + 1);
             Array errorsArr = new object[n + 1];
             Array serverH   = new object[n + 1];
             for (int j = 1; j <= n; j++)
             {
                 var item = list[j];
                 itemArr.SetValue(item.Tag, j);
                 clientH.SetValue(j, j);
             }
             _group.OPCItems.AddItems(n, ref itemArr, ref clientH, out serverH, out errorsArr);
             int m = 1;
             for (int j = 1; j <= n; j++)
             {
                 if (((int)errorsArr.GetValue(j)) == 0)
                 {
                     m++;
                 }
             }
             _itemsList = new OpcItem[m];
             int k = 1;
             for (int j = 1; j <= n; j++)
             {
                 if (((int)errorsArr.GetValue(j)) == 0)
                 {
                     _itemsList[k] = list[j];
                     _itemsList[k++].ServerHandler = (int)serverH.GetValue(j);
                 }
             }
         }
         return(true);
     }
     catch (Exception ex)
     {
         Logger.AddError("Ошибка подготовки серверной группы", ex);
         return(IsConnected = false);
     }
 }