Beispiel #1
0
        private Boolean Add(IModbusCoilsTag tag)
        {
            if (tag.Address == null)
            {
                return(false);
            }
            if (tag.Address.Table != Table.Coils)
            {
                return(false);
            }
            if (tag.QuantityOfCoils > MaxQuantityOfCoils)
            {
                return(false);
            }
            if (Tags.Count == 0)
            {
                Tags.Add(tag);
                this.Address         = tag.Address;
                this.QuantityOfCoils = tag.QuantityOfCoils;
                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.QuantityOfCoils - 1, tag.Address.Index + tag.QuantityOfCoils - 1));
            UInt16  NewQuantityOfCoils = Convert.ToUInt16(LastIndex - FirstIndex + 1);

            if (NewQuantityOfCoils > MaxQuantityOfCoils)
            {
                return(false);
            }

            Tags.Add(tag);
            this.Address         = NewAddress;
            this.QuantityOfCoils = NewQuantityOfCoils;
            return(true);
        }
Beispiel #2
0
        private Boolean Add(IModbusCoilsTag tag)
        {
            if (tag.Address == null)
                return false;
            if (tag.Address.Table != Table.Coils)
                return false;
            if (tag.QuantityOfCoils > MaxQuantityOfCoils)
                return false;
            if (Tags.Count == 0)
            {
                Tags.Add(tag);
                this.Address = tag.Address;
                this.QuantityOfCoils = tag.QuantityOfCoils;
                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.QuantityOfCoils - 1, tag.Address.Index + tag.QuantityOfCoils - 1));
            UInt16 NewQuantityOfCoils = Convert.ToUInt16(LastIndex - FirstIndex + 1);

            if (NewQuantityOfCoils > MaxQuantityOfCoils)
                return false;

            Tags.Add(tag);
            this.Address = NewAddress;
            this.QuantityOfCoils = NewQuantityOfCoils;
            return true;
        }