public bool AddItems(IList <TagMetaData> items) { int count = items.Count; if (_items == null) { _items = new List <ITag>(count); _activeList = new HashSet <short>(); } lock (_server.SyncRoot) { for (int i = 0; i < count; i++) { ITag dataItem = null; TagMetaData meta = items[i]; if (meta.GroupID == this._id) { switch (meta.DataType) { case DataType.BOOL: dataItem = new BoolTag(meta.ID, _reader.GetDeviceAddress(meta.Address), this); break; case DataType.BYTE: dataItem = new ByteTag(meta.ID, _reader.GetDeviceAddress(meta.Address), this); break; case DataType.WORD: case DataType.SHORT: dataItem = new ShortTag(meta.ID, _reader.GetDeviceAddress(meta.Address), this); break; case DataType.TIME: case DataType.INT: dataItem = new IntTag(meta.ID, _reader.GetDeviceAddress(meta.Address), this); break; case DataType.FLOAT: dataItem = new FloatTag(meta.ID, _reader.GetDeviceAddress(meta.Address), this); break; case DataType.STR: dataItem = new StringTag(meta.ID, _reader.GetDeviceAddress(meta.Address), this); break; } if (dataItem != null) { _items.Add(dataItem); _server.AddItemIndex(meta.Name, dataItem); _activeList.Add(meta.ID); } } } } _items.Sort(rc); _items.TrimExcess(); return(true); }
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); }