Exemplo n.º 1
0
        private void AddItems(List <string> p_ItemIds)
        {
            int l_ItemClientHandle = 0;

            OPCItemDef[]    l_ItemDef = new OPCItemDef[p_ItemIds.Count];
            OPCItemResult[] l_AddRes;

            foreach (string l_ItemName in p_ItemIds)
            {
                l_ItemDef[l_ItemClientHandle] = new OPCItemDef(l_ItemName, false, l_ItemClientHandle, VarEnum.VT_BSTR);
                l_ItemClientHandle++;
            }

            m_Group.AddItems(l_ItemDef, out l_AddRes);

            l_ItemClientHandle = 0;
            foreach (string l_ItemName in p_ItemIds)
            {
                if (l_AddRes[l_ItemClientHandle].Error == HResults.S_OK)
                {
                    Dictionary <string, string> l_ItemProps = new Dictionary <string, string>();
                    l_ItemProps.Add(ServerModel.ITEM_PROP_ID_KEY, m_Server.GetItemID(l_ItemName));
                    l_ItemProps.Add(ServerModel.ITEM_PROP_TYPE_KEY, OPCUtility.TypeToString((int)l_AddRes[l_ItemClientHandle].CanonicalDataType));

                    m_ServerModel.AddItem(l_ItemClientHandle, l_AddRes[l_ItemClientHandle].HandleServer, l_ItemProps);
                }

                l_ItemClientHandle++;
            }
        }
        private void AddItems(List <string> p_ItemIds)
        {
            int l_ItemClientHandle = 0;

            OpcItemDef[]    l_ItemDef = new OpcItemDef[p_ItemIds.Count];
            OpcItemResult[] l_AddRes;

            foreach (string l_ItemName in p_ItemIds)
            {
                l_ItemDef[l_ItemClientHandle] = new OpcItemDef(l_ItemName, false, l_ItemClientHandle, VarEnum.VT_BSTR);
                l_ItemClientHandle++;
            }

            _group.AddItems(l_ItemDef, out l_AddRes);

            l_ItemClientHandle = 0;
            foreach (string l_ItemName in p_ItemIds)
            {
                if (l_AddRes[l_ItemClientHandle].Error == HResults.S_OK)
                {
                    Dictionary <string, string> l_ItemProps = new Dictionary <string, string>();
                    l_ItemProps.Add(CModel.ServerModel.ItemPropIdKey, _server.GetItemID(l_ItemName));
                    l_ItemProps.Add(CModel.ServerModel.ItemPropTypeKey, OpcUtility.TypeToString((int)l_AddRes[l_ItemClientHandle].CanonicalDataType));

                    _serverModel.AddItem(l_ItemClientHandle, l_AddRes[l_ItemClientHandle].HandleServer, l_ItemProps);
                }

                l_ItemClientHandle++;
            }
        }