Пример #1
0
        private void Classificator(Tag addingTag)
        {
            if (addingTag.TagDirection == Direction.Write)
            {
                if (!allWriteTags.ContainsKey(addingTag.Name))
                {
                    allWriteTags.Add(addingTag.Name, addingTag);
                }
                return;
            }
            if (addingTag.InnerTag is BoolTag)
            {
                if (!allBoolTags.ContainsKey(addingTag.Name))
                {
                    allBoolTags.Add(addingTag.Name, (addingTag.InnerTag as BoolTag));
                }
            }
            else if (addingTag.InnerTag is UshortTag)
            {
                allUshortTags.Add(addingTag.Name, (addingTag.InnerTag as UshortTag));
            }
            else if (addingTag.InnerTag is FloatTag)
            {
                allFloatTags.Add(addingTag.Name, (addingTag.InnerTag as FloatTag));
            }

            if (addingTag.InnerTag.Function == StatusFunction.CoilStatus)
            {
                if (!CoilStatuses.ContainsKey(addingTag.Name))
                {
                    CoilStatuses.Add(addingTag.Name, (addingTag.InnerTag));
                }
            }
            else if (addingTag.InnerTag.Function == StatusFunction.InputStatus)
            {
                if (!InputStatuses.ContainsKey(addingTag.Name))
                {
                    InputStatuses.Add(addingTag.Name, (addingTag.InnerTag));
                }
            }
            else if (addingTag.InnerTag.Function == RegisterFunction.HoldingRegister)
            {
                if (!InputStatuses.ContainsKey(addingTag.Name))
                {
                    HoldingRegisters.Add(addingTag.Name, (addingTag.InnerTag));
                }
            }
            else if (addingTag.InnerTag.Function == RegisterFunction.InputRegister)
            {
                if (!InputStatuses.ContainsKey(addingTag.Name))
                {
                    InputRegisters.Add(addingTag.Name, (addingTag.InnerTag));
                }
            }

            addingTag.TagStatusChanged += delegate(Tag sender, object value, bool quality)
            {
                TagStatusChanged?.Invoke(sender, value, quality);
            };
        }
Пример #2
0
 public void CalculateParseAddresses()
 {
     CoilStatuses.CalculteParseAddresses();
     InputStatuses.CalculteParseAddresses();
     HoldingRegisters.CalculteParseAddresses();
     InputRegisters.CalculteParseAddresses();
 }
Пример #3
0
 /// <summary>
 /// Method for assigning value to modbus input registers
 /// </summary>
 /// <param name="registers">
 /// Modbus input registers to which variable should be added
 /// </param>
 public void AssignValueToRegisters(InputRegisters registers)
 {
     for (int i = Offset; i < Offset + Data.Length; i++)
     {
         registers[i] = Data[i - Offset];
     }
 }
Пример #4
0
        public void UpdateValue(Data data, bool readOnlyOverride = false)
        {
            var normalisedAddress = AddressTools.AddressNormalisation(data.Address);
            var addressType       = AddressTools.AddressType(data.Address);

            if (addressType != data.Type)
            {
                throw new DataTypeDoesNotMatchAddressException(data.Address.ToString());
            }

            if (ValueExists(data.Address))
            {
                switch (addressType)
                {
                case DataType.Coil:
                    Coils.Find(c => c.Address == normalisedAddress).Update(data.Value, readOnlyOverride);
                    break;

                case DataType.DiscreteInput:
                    DiscreteInputs.Find(c => c.Address == normalisedAddress).Update(data.Value, readOnlyOverride);
                    break;

                case DataType.InputRegister:
                    InputRegisters.Find(c => c.Address == normalisedAddress).Update(data.Value, readOnlyOverride);
                    break;

                case DataType.HoldingRegister:
                    HoldingRegisters.Find(c => c.Address == normalisedAddress).Update(data.Value, readOnlyOverride);
                    break;
                }
            }
            else
            {
                var normalisedData = Data.Create(normalisedAddress, data.Type);

                switch (addressType)
                {
                case DataType.Coil:
                    Coils.Add(normalisedData);
                    break;

                case DataType.DiscreteInput:
                    DiscreteInputs.Add(normalisedData);
                    break;

                case DataType.InputRegister:
                    InputRegisters.Add(normalisedData);
                    break;

                case DataType.HoldingRegister:
                    HoldingRegisters.Add(normalisedData);
                    break;
                }
            }
        }
Пример #5
0
        public void Read(BinaryReader binaryReader)
        {
            InputRegisters.Clear();
            IsNull = binaryReader.ReadBoolean();

            if (IsNull)
            {
                return;
            }
            else
            {
                var length = binaryReader.ReadInt32();

                for (var i = 0; length > i; i++)
                {
                    var inputRegister = new MODBUSMaster_InputRegister();
                    inputRegister.Read(binaryReader);
                    InputRegisters.Add(inputRegister);
                }
            }
        }
Пример #6
0
        public bool ValueExists(int address)
        {
            var normalisedAddress = AddressTools.AddressNormalisation(address);
            var addressType       = AddressTools.AddressType(address);

            switch (addressType)
            {
            case DataType.Coil:
                return(Coils.Exists(c => c.Address == normalisedAddress));

            case DataType.DiscreteInput:
                return(DiscreteInputs.Exists(c => c.Address == normalisedAddress));

            case DataType.InputRegister:
                return(InputRegisters.Exists(c => c.Address == normalisedAddress));

            case DataType.HoldingRegister:
                return(HoldingRegisters.Exists(c => c.Address == normalisedAddress));
            }

            return(false);
        }
Пример #7
0
        public Slave ToModel()
        {
            return(new Slave()
            {
                SlaveId = SlaveId,

                HoldingRegisters = HoldingRegisters
                                   .Where(r => r.Value != 0)
                                   .Select(r => new Point <ushort>()
                {
                    Address = r.Address,
                    Value = r.Value
                }).ToArray(),

                InputRegisters = InputRegisters
                                 .Where(r => r.Value != 0)
                                 .Select(r => new Point <ushort>()
                {
                    Address = r.Address,
                    Value = r.Value
                }).ToArray(),

                Inputs = CoilInputs
                         .Where(r => r.Value)
                         .Select(d => new Point <bool>
                {
                    Address = d.Address,
                    Value = d.Value
                }).ToArray(),

                Discretes = CoilDiscretes
                            .Where(r => r.Value)
                            .Select(d => new Point <bool>
                {
                    Address = d.Address,
                    Value = d.Value
                }).ToArray(),
            });
        }
Пример #8
0
 public MODBUSMaster_InputRegisterArray AddInputRegister(MODBUSMaster_InputRegister inputRegister)
 {
     InputRegisters.Add(inputRegister);
     return(this);
 }
Пример #9
0
 public override string ToString()
 {
     return(string.Join("|", InputRegisters.Select(inputRegister => inputRegister.ToString())));
 }
Пример #10
0
        private void Classificator(Tag addingTag)
        {
            if (addingTag.TagDirection == Direction.Write)
            {
                if (!allWriteTags.ContainsKey(addingTag.Name))
                {
                    allWriteTags.Add(addingTag.Name, addingTag);
                }
                return;
            }
            if (addingTag.InnerTag is BoolTag)
            {
                if (!allBoolTags.ContainsKey(addingTag.Name))
                {
                    allBoolTags.Add(addingTag.Name, (addingTag.InnerTag as BoolTag));
                }
            }
            else if (addingTag.InnerTag is UshortTag)
            {
                allUshortTags.Add(addingTag.Name, (addingTag.InnerTag as UshortTag));
            }
            else if (addingTag.InnerTag is FloatTag)
            {
                allFloatTags.Add(addingTag.Name, (addingTag.InnerTag as FloatTag));
            }
            else if (addingTag.InnerTag is UintTag)
            {
                allUintTags.Add(addingTag.Name, (addingTag.InnerTag as UintTag));
            }

            if (addingTag.InnerTag.Function == StatusFunction.CoilStatus)
            {
                if (!CoilStatuses.ContainsKey(addingTag.Name))
                {
                    CoilStatuses.Add(addingTag.Name, (addingTag.InnerTag));
                }
            }
            else if (addingTag.InnerTag.Function == StatusFunction.InputStatus)
            {
                if (!InputStatuses.ContainsKey(addingTag.Name))
                {
                    InputStatuses.Add(addingTag.Name, (addingTag.InnerTag));
                }
            }
            else if (addingTag.InnerTag.Function == RegisterFunction.HoldingRegister)
            {
                if (!HoldingRegisters.ContainsKey(addingTag.Name))
                {
                    HoldingRegisters.Add(addingTag.Name, (addingTag.InnerTag));
                }
            }
            else if (addingTag.InnerTag.Function == RegisterFunction.InputRegister)
            {
                if (!InputRegisters.ContainsKey(addingTag.Name))
                {
                    InputRegisters.Add(addingTag.Name, (addingTag.InnerTag));
                }
            }

            addingTag.TagStatusChanged += (sender, e) =>
            {
                TagStatusChanged?.Invoke(sender, EventArgs.Empty);
            };
        }
Пример #11
0
 public InputRegisterArray AddInputRegister(InputRegister inputRegister)
 {
     InputRegisters.Add(inputRegister);
     return(this);
 }
Пример #12
0
        public UInt16 GetInputRegister(UInt16 address)
        {
            var finded = InputRegisters.Find(x => x.Address == address);

            return(finded.Value);
        }
Пример #13
0
        public void SetInputRegister(UInt16 address, UInt16 value)
        {
            int index = InputRegisters.FindIndex(x => x.Address == address);

            InputRegisters[index].Value = value;
        }
Пример #14
0
 public void AddInputRegister(Register register)//Register<UInt16> register)
 {
     InputRegisters.Add(register);
     InputRegsCount = (UInt16)InputRegisters.Count;
 }