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); }; }
public void CalculateParseAddresses() { CoilStatuses.CalculteParseAddresses(); InputStatuses.CalculteParseAddresses(); HoldingRegisters.CalculteParseAddresses(); InputRegisters.CalculteParseAddresses(); }
/// <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]; } }
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; } } }
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); } } }
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); }
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(), }); }
public MODBUSMaster_InputRegisterArray AddInputRegister(MODBUSMaster_InputRegister inputRegister) { InputRegisters.Add(inputRegister); return(this); }
public override string ToString() { return(string.Join("|", InputRegisters.Select(inputRegister => inputRegister.ToString()))); }
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); }; }
public InputRegisterArray AddInputRegister(InputRegister inputRegister) { InputRegisters.Add(inputRegister); return(this); }
public UInt16 GetInputRegister(UInt16 address) { var finded = InputRegisters.Find(x => x.Address == address); return(finded.Value); }
public void SetInputRegister(UInt16 address, UInt16 value) { int index = InputRegisters.FindIndex(x => x.Address == address); InputRegisters[index].Value = value; }
public void AddInputRegister(Register register)//Register<UInt16> register) { InputRegisters.Add(register); InputRegsCount = (UInt16)InputRegisters.Count; }