Exemplo n.º 1
0
 public void CalculateParseAddresses()
 {
     CoilStatuses.CalculteParseAddresses();
     InputStatuses.CalculteParseAddresses();
     HoldingRegisters.CalculteParseAddresses();
     InputRegisters.CalculteParseAddresses();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Method for assigning value to modbus holding registers
 /// </summary>
 /// <param name="registers">
 /// Modbus holding registers to which variable should be added
 /// </param>
 public void AssignValueToRegisters(HoldingRegisters registers)
 {
     for (int i = Offset; i < Offset + Data.Length; i++)
     {
         registers[i] = Data[i - Offset];
     }
 }
Exemplo n.º 3
0
        public void SetHoldingRegister(UInt16 address, UInt16 value)
        {
            int index = HoldingRegisters.FindIndex(x => x.Address == address);

            HoldingRegisters[index].Value = value;
            HoldingRegisterChanged(address, value);
        }
Exemplo n.º 4
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);
            };
        }
Exemplo n.º 5
0
        public void Read(BinaryReader binaryReader)
        {
            HoldingRegisters.Clear();
            IsNull = binaryReader.ReadBoolean();

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

                for (var i = 0; length > i; i++)
                {
                    var holdingRegister = new MODBUSMaster_HoldingRegister();
                    holdingRegister.Read(binaryReader);
                    HoldingRegisters.Add(holdingRegister);
                }
            }
        }
Exemplo n.º 6
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(),
            });
        }
Exemplo n.º 7
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);
            };
        }
Exemplo n.º 8
0
        public UInt16 GetHoldingRegister(UInt16 address)
        {
            var finded = HoldingRegisters.Find(x => x.Address == address);

            return(finded.Value);
        }
Exemplo n.º 9
0
 public void AddHoldingRegister(Register register)
 {
     HoldingRegisters.Add(register);
     HoldingRegsCount = (UInt16)HoldingRegisters.Count;
 }
Exemplo n.º 10
0
 public MODBUSMaster_HoldingRegisterArray AddHoldingRegister(MODBUSMaster_HoldingRegister holdingRegister)
 {
     HoldingRegisters.Add(holdingRegister);
     return(this);
 }
Exemplo n.º 11
0
 public override string ToString()
 {
     return(string.Join("|", HoldingRegisters.Select(holdingRegister => holdingRegister.ToString())));
 }
Exemplo n.º 12
0
 public HoldingRegisterArray AddHoldingRegister(HoldingRegister holdingRegister)
 {
     HoldingRegisters.Add(holdingRegister);
     return(this);
 }