示例#1
0
        public bool AddItems(IList <TagMetaData> items)
        {
            int count = items.Count;

            if (_items == null)
            {
                _items = new List <ITag>(count);
            }
            lock (_server.SyncRoot)
            {
                for (int i = 0; i < count; i++)
                {
                    ITag        dataItem = null;
                    TagMetaData meta     = items[i];
                    if (meta.GroupID == this._id)
                    {
                        DeviceAddress addr = _plcReader.GetDeviceAddress(meta.Address);
                        if (addr.DataSize == 0)
                        {
                            addr.DataSize = meta.Size;
                        }
                        if (addr.VarType == DataType.NONE)
                        {
                            addr.VarType = meta.DataType;
                        }
                        if (addr.VarType != DataType.BOOL)
                        {
                            addr.Bit = 0;
                        }
                        switch (meta.DataType)
                        {
                        case DataType.BOOL:
                            dataItem = new BoolTag(meta.ID, addr, this);
                            break;

                        case DataType.BYTE:
                            dataItem = new ByteTag(meta.ID, addr, this);
                            break;

                        case DataType.WORD:
                        case DataType.SHORT:
                            dataItem = new ShortTag(meta.ID, addr, this);
                            break;

                        case DataType.TIME:
                        case DataType.INT:
                            dataItem = new IntTag(meta.ID, addr, this);
                            break;

                        case DataType.FLOAT:
                            dataItem = new FloatTag(meta.ID, addr, this);
                            break;

                        case DataType.STR:
                            dataItem = new StringTag(meta.ID, addr, this);
                            break;
                        }
                        if (dataItem != null)
                        {
                            //dataItem.Active = meta.Active;
                            _items.Add(dataItem);
                            _server.AddItemIndex(meta.Name, dataItem);
                        }
                    }
                }
            }
            _items.TrimExcess();
            _items.Sort();
            UpdatePDUArea();
            return(true);
        }