/// <summary> /// Reads a single tag /// </summary> /// <param name="tag">Tag to read</param> /// <returns>True if the read was successful</returns> /// <remarks>This is not the preferred method of updating tag information. If you have /// multiple tags that you want to update, use the <see cref="UpdateGroup"/> method.</remarks> public bool ReadTag(ITag tag) { lock (_lockObject) { LogixTag lgxTag = tag as LogixTag; if (lgxTag == null) { throw new ArgumentException(Resources.ErrorStrings.IncorrectArgTagType, "tag"); } ReadDataServiceReply lgxRead = LogixServices.ReadLogixData(_session, lgxTag.Address, (ushort)lgxTag.Elements); if (lgxRead == null || lgxRead.Data == null) { if (lgxRead != null) { lgxTag.SetTagError(lgxRead.ByteStatus); } lgxTag.LastError = Resources.ErrorStrings.TagNotFound + _ipAddress; lgxTag.LastErrorNumber = (int)LogixErrors.TagNotFound; return(false); } lgxTag.SetTagError(lgxRead.ByteStatus); CIPType tagType = (CIPType)lgxRead.DataType; byte[] temp = new byte[lgxRead.Data.Length + 2]; Buffer.BlockCopy(BitConverter.GetBytes(lgxRead.DataType), 0, temp, 0, 2); Buffer.BlockCopy(lgxRead.Data, 0, temp, 2, lgxRead.Data.Length); lgxTag.UpdateValue(temp); uint offset = (uint)lgxRead.Data.Length; if (lgxRead.Status == 0x06) { //We are going to have to request more data... while (lgxRead.Status == 0x06) { lgxRead = LogixServices.ReadLogixDataFragmented(_session, lgxTag.Address, (ushort)lgxTag.Elements, offset); lgxTag.SetTagError(lgxRead.ByteStatus); tagType = (CIPType)lgxRead.DataType; temp = new byte[lgxRead.Data.Length + 2]; Buffer.BlockCopy(BitConverter.GetBytes(lgxRead.DataType), 0, temp, 0, 2); Buffer.BlockCopy(lgxRead.Data, 0, temp, 2, lgxRead.Data.Length); lgxTag.UpdateValue(temp, offset); offset += (uint)lgxRead.Data.Length; } } } //End Lock return(true); }
public UserAttribut(string name, CIPType type) { this.name = name; this.type = type; }