private Boolean Add(IModbusHoldingRegistersTag tag) { if (tag.Address == null) { return(false); } if (tag.Address.Table != Table.HoldingRegisters) { return(false); } if (tag.QuantityOfRegisters > MaxQuantityOfRegisters) { return(false); } if (Tags.Count == 0) { Tags.Add(tag); this.Address = tag.Address; this.QuantityOfRegisters = tag.QuantityOfRegisters; return(true); } Address NewAddress = this.Address < tag.Address ? this.Address : tag.Address; UInt16 FirstIndex = NewAddress.Index; UInt16 LastIndex = Convert.ToUInt16(Math.Max(this.Address.Index + this.QuantityOfRegisters - 1, tag.Address.Index + tag.QuantityOfRegisters - 1)); UInt16 NewQuantityOfRegisters = Convert.ToUInt16(LastIndex - FirstIndex + 1); if (NewQuantityOfRegisters > MaxQuantityOfRegisters) { return(false); } Tags.Add(tag); this.Address = NewAddress; this.QuantityOfRegisters = NewQuantityOfRegisters; return(true); }
private Boolean Add(IModbusHoldingRegistersTag tag) { if (tag.Address == null) return false; if (tag.Address.Table != Table.HoldingRegisters) return false; if (tag.QuantityOfRegisters > MaxQuantityOfRegisters) return false; if (Tags.Count == 0) { Tags.Add(tag); this.Address = tag.Address; this.QuantityOfRegisters = tag.QuantityOfRegisters; return true; } Address NewAddress = this.Address < tag.Address ? this.Address : tag.Address; UInt16 FirstIndex = NewAddress.Index; UInt16 LastIndex = Convert.ToUInt16(Math.Max(this.Address.Index + this.QuantityOfRegisters - 1, tag.Address.Index + tag.QuantityOfRegisters - 1)); UInt16 NewQuantityOfRegisters = Convert.ToUInt16(LastIndex - FirstIndex + 1); if (NewQuantityOfRegisters > MaxQuantityOfRegisters) return false; Tags.Add(tag); this.Address = NewAddress; this.QuantityOfRegisters = NewQuantityOfRegisters; return true; }