diff --git a/Examples/Program.cs b/Examples/Program.cs index 93736cf..4c516d0 100644 --- a/Examples/Program.cs +++ b/Examples/Program.cs @@ -30,9 +30,9 @@ namespace Examples { //reading a value from the register collection Console.WriteLine($"BitValue is: {registers.BitValue}"); - interf.GetRegister(nameof(registers.TestInt16)).PropertyChanged += (s, e) => { + interf.GetRegister(nameof(registers.TestBool1)).PropertyChanged += (s, e) => { Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine(interf.GetRegister(nameof(registers.TestInt16)).StringValue); + Console.WriteLine(interf.GetRegister(nameof(registers.TestBool1)).StringValue); Console.ResetColor(); }; @@ -44,9 +44,6 @@ namespace Examples { await Task.Delay(2000); - //inverts the boolean register - await interf.SetRegisterAsync(nameof(registers.TestBool1), !registers.TestBool1); - Console.WriteLine("Testregister was toggled"); //adds 10 each time the plc connects to the PLCs INT regĂ­ster diff --git a/Examples/TestRegisters.cs b/Examples/TestRegisters.cs index 9295e7b..7a37431 100644 --- a/Examples/TestRegisters.cs +++ b/Examples/TestRegisters.cs @@ -7,7 +7,7 @@ namespace Examples { public class TestRegisters : RegisterCollectionBase { //corresponds to a R100 boolean register in the PLC - [Register(100, RegisterType.R)] + [Register(1000, RegisterType.R)] public bool TestBool1 { get; private set; } //corresponds to a XD input of the PLC @@ -42,6 +42,9 @@ namespace Examples { [Register(1204, 9, BitCount.B16)] public bool BitValue { get; private set; } + [Register(1204, 5, BitCount.B16)] + public bool FillTest { get; private set; } + //corresponds to a DT7012 - DT7013 as a 32bit time value that gets parsed as a timespan (TIME) //the smallest value to communicate to the PLC is 10ms [Register(7012)] diff --git a/MewtocolNet/Mewtocol/DynamicInterface.cs b/MewtocolNet/Mewtocol/DynamicInterface.cs index 6aa0dd5..be0786f 100644 --- a/MewtocolNet/Mewtocol/DynamicInterface.cs +++ b/MewtocolNet/Mewtocol/DynamicInterface.cs @@ -95,63 +95,49 @@ namespace MewtocolNet { var lastVal = shortReg.Value; var readout = (await ReadNumRegister(shortReg)).Register.Value; if (lastVal != readout) { - shortReg.LastValue = readout; InvokeRegisterChanged(shortReg); - shortReg.TriggerNotifyChange(); } } if (reg is NRegister ushortReg) { var lastVal = ushortReg.Value; var readout = (await ReadNumRegister(ushortReg)).Register.Value; if (lastVal != readout) { - ushortReg.LastValue = readout; InvokeRegisterChanged(ushortReg); - ushortReg.TriggerNotifyChange(); } } if (reg is NRegister intReg) { var lastVal = intReg.Value; var readout = (await ReadNumRegister(intReg)).Register.Value; if (lastVal != readout) { - intReg.LastValue = readout; InvokeRegisterChanged(intReg); - intReg.TriggerNotifyChange(); } } if (reg is NRegister uintReg) { var lastVal = uintReg.Value; var readout = (await ReadNumRegister(uintReg)).Register.Value; if (lastVal != readout) { - uintReg.LastValue = readout; InvokeRegisterChanged(uintReg); - uintReg.TriggerNotifyChange(); } } if (reg is NRegister floatReg) { var lastVal = floatReg.Value; var readout = (await ReadNumRegister(floatReg)).Register.Value; if (lastVal != readout) { - floatReg.LastValue = readout; InvokeRegisterChanged(floatReg); - floatReg.TriggerNotifyChange(); } } if (reg is NRegister tsReg) { var lastVal = tsReg.Value; var readout = (await ReadNumRegister(tsReg)).Register.Value; if (lastVal != readout) { - tsReg.LastValue = readout; InvokeRegisterChanged(tsReg); - tsReg.TriggerNotifyChange(); } } if (reg is BRegister boolReg) { var lastVal = boolReg.Value; var readout = (await ReadBoolRegister(boolReg)).Register.Value; if (lastVal != readout) { - boolReg.LastValue = readout; InvokeRegisterChanged(boolReg); - boolReg.TriggerNotifyChange(); } } if (reg is SRegister stringReg) { @@ -159,7 +145,6 @@ namespace MewtocolNet { var readout = (await ReadStringRegister(stringReg)).Register.Value; if (lastVal != readout) { InvokeRegisterChanged(stringReg); - stringReg.TriggerNotifyChange(); } } @@ -200,30 +185,60 @@ namespace MewtocolNet { /// A naming definition for QOL, doesn't effect PLC and is optional public void AddRegister (int _address, RegisterType _type, string _name = null) { + Register toAdd = null; + //as number registers if (_type == RegisterType.DT_short) { - Registers.Add(_address, new NRegister(_address, _name)); - return; + toAdd = new NRegister(_address, _name); } if (_type == RegisterType.DT_ushort) { - Registers.Add(_address, new NRegister(_address, _name)); - return; + toAdd = new NRegister(_address, _name); } if (_type == RegisterType.DDT_int) { - Registers.Add(_address, new NRegister(_address, _name)); - return; + toAdd = new NRegister(_address, _name); } if (_type == RegisterType.DDT_uint) { - Registers.Add(_address, new NRegister(_address, _name)); - return; + toAdd = new NRegister(_address, _name); } if (_type == RegisterType.DDT_float) { - Registers.Add(_address, new NRegister(_address, _name)); - return; + toAdd = new NRegister(_address, _name); } - //as bool registers - Registers.Add(_address, new BRegister(_address, _type, _name)); + if(toAdd == null) { + toAdd = new BRegister(_address, _type, _name); + } + + Registers.Add(_address, toAdd); + + } + + internal void AddRegister (Type _colType, int _address, RegisterType _type, string _name = null) { + + Register toAdd = null; + + //as number registers + if (_type == RegisterType.DT_short) { + toAdd = new NRegister(_address, _name); + } + if (_type == RegisterType.DT_ushort) { + toAdd = new NRegister(_address, _name); + } + if (_type == RegisterType.DDT_int) { + toAdd = new NRegister(_address, _name); + } + if (_type == RegisterType.DDT_uint) { + toAdd = new NRegister(_address, _name); + } + if (_type == RegisterType.DDT_float) { + toAdd = new NRegister(_address, _name); + } + + if (toAdd == null) { + toAdd = new BRegister(_address, _type, _name); + } + + toAdd.collectionType = _colType; + Registers.Add(_address, toAdd); } @@ -248,6 +263,17 @@ namespace MewtocolNet { } + internal void AddRegister (Type _colType, SpecialAddress _spAddress, RegisterType _type, string _name = null) { + + var reg = new BRegister(_spAddress, _type, _name); + + reg.collectionType = _colType; + + //as bool registers + Registers.Add((int)_spAddress, reg); + + } + /// /// Adds a PLC memory register to the watchlist /// The registers can be read back by attaching @@ -265,7 +291,7 @@ namespace MewtocolNet { /// A naming definition for QOL, doesn't effect PLC and is optional /// The address of the register in the PLCs memory /// The length of the string (Can be ignored for other types) - public void AddRegister(int _address, int _length = 1, string _name = null, bool _isBitwise = false) { + public void AddRegister(int _address, int _length = 1, string _name = null) { Type regType = typeof(T); @@ -274,18 +300,16 @@ namespace MewtocolNet { } if (Registers.Any(x => x.Key == _address)) { - throw new NotSupportedException($"Cannot add a register multiple times, " + $"make sure that all register attributes or AddRegister assignments have different adresses."); - } if (regType == typeof(short)) { - Registers.Add(_address, new NRegister(_address, _name, _isBitwise)); + Registers.Add(_address, new NRegister(_address, _name)); } else if (regType == typeof(ushort)) { Registers.Add(_address, new NRegister(_address, _name)); } else if (regType == typeof(int)) { - Registers.Add(_address, new NRegister(_address, _name, _isBitwise)); + Registers.Add(_address, new NRegister(_address, _name)); } else if (regType == typeof(uint)) { Registers.Add(_address, new NRegister(_address, _name)); } else if (regType == typeof(float)) { @@ -303,6 +327,56 @@ namespace MewtocolNet { } + internal void AddRegister (Type _colType, int _address, int _length = 1, string _name = null, bool _isBitwise = false) { + + Type regType = typeof(T); + + if (regType != typeof(string) && _length != 1) { + throw new NotSupportedException($"_lenght parameter only allowed for register of type string"); + } + + if (Registers.Any(x => x.Key == _address) && !_isBitwise) { + throw new NotSupportedException($"Cannot add a register multiple times, " + + $"make sure that all register attributes or AddRegister assignments have different adresses."); + } + + if (Registers.Any(x => x.Key == _address) && _isBitwise) { + return; + } + + Register reg = null; + + if (regType == typeof(short)) { + reg = new NRegister(_address, _name, _isBitwise); + } else if (regType == typeof(ushort)) { + reg = new NRegister(_address, _name); + } else if (regType == typeof(int)) { + reg = new NRegister(_address, _name, _isBitwise); + } else if (regType == typeof(uint)) { + reg = new NRegister(_address, _name); + } else if (regType == typeof(float)) { + reg = new NRegister(_address, _name); + } else if (regType == typeof(string)) { + reg = new SRegister(_address, _length, _name); + } else if (regType == typeof(TimeSpan)) { + reg = new NRegister(_address, _name); + } else if (regType == typeof(bool)) { + reg = new BRegister(_address, RegisterType.R, _name); + } + + + if (reg == null) { + throw new NotSupportedException($"The type {regType} is not allowed for Registers \n" + + $"Allowed are: short, ushort, int, uint, float and string"); + } else { + + reg.collectionType = _colType; + + Registers.Add(_address, reg); + } + + } + #endregion #region Register accessing diff --git a/MewtocolNet/Mewtocol/MewtocolInterface.cs b/MewtocolNet/Mewtocol/MewtocolInterface.cs index 396afe5..51384e8 100644 --- a/MewtocolNet/Mewtocol/MewtocolInterface.cs +++ b/MewtocolNet/Mewtocol/MewtocolInterface.cs @@ -92,7 +92,7 @@ namespace MewtocolNet { /// public int CycleTimeMs { get { return cycleTimeMs; } - set { + private set { cycleTimeMs = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CycleTimeMs))); } @@ -234,43 +234,43 @@ namespace MewtocolNet { if (prop.PropertyType == typeof(bool) && cAttribute.AssignedBitIndex == -1) { if (cAttribute.SpecialAddress == SpecialAddress.None) { - AddRegister(cAttribute.MemoryArea, cAttribute.RegisterType, _name: propName); + AddRegister(collection.GetType(), cAttribute.MemoryArea, cAttribute.RegisterType, _name: propName); } else { - AddRegister(cAttribute.SpecialAddress, cAttribute.RegisterType, _name: propName); + AddRegister(collection.GetType(), cAttribute.SpecialAddress, cAttribute.RegisterType, _name: propName); } } if (prop.PropertyType == typeof(short)) { - AddRegister(cAttribute.MemoryArea, _name: propName); + AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: propName); } if (prop.PropertyType == typeof(ushort)) { - AddRegister(cAttribute.MemoryArea, _name: propName); + AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: propName); } if (prop.PropertyType == typeof(int)) { - AddRegister(cAttribute.MemoryArea, _name: propName); + AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: propName); } if (prop.PropertyType == typeof(uint)) { - AddRegister(cAttribute.MemoryArea, _name: propName); + AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: propName); } if (prop.PropertyType == typeof(float)) { - AddRegister(cAttribute.MemoryArea, _name: propName); + AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: propName); } if (prop.PropertyType == typeof(string)) { - AddRegister(cAttribute.MemoryArea, cAttribute.StringLength, _name: propName); + AddRegister(collection.GetType(), cAttribute.MemoryArea, cAttribute.StringLength, _name: propName); } //read number as bit array if (prop.PropertyType == typeof(BitArray)) { if (cAttribute.BitCount == BitCount.B16) { - AddRegister(cAttribute.MemoryArea, _name: propName, _isBitwise: true); + AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: propName, _isBitwise: true); } else { - AddRegister(cAttribute.MemoryArea, _name: propName, _isBitwise: true); + AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: propName, _isBitwise: true); } } @@ -279,15 +279,22 @@ namespace MewtocolNet { if (prop.PropertyType == typeof(bool) && cAttribute.AssignedBitIndex != -1) { if (cAttribute.BitCount == BitCount.B16) { - AddRegister(cAttribute.MemoryArea, _name: propName, _isBitwise: true); + AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: propName, _isBitwise: true); } else { - AddRegister(cAttribute.MemoryArea, _name: propName, _isBitwise: true); + AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: propName, _isBitwise: true); } + //attach for bools to be read when bitregister + //RegisterChanged += (reg) => { + // if (reg.Name == propName) { + // prop.SetValue() + // } + //}; + } if (prop.PropertyType == typeof(TimeSpan)) { - AddRegister(cAttribute.MemoryArea, _name: propName); + AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: propName); } } @@ -298,6 +305,40 @@ namespace MewtocolNet { RegisterChanged += (reg) => { + //if the register is also used bitwise assign the boolean bit value to the according prop + if(reg.isUsedBitwise) { + + for (int i = 0; i < props.Length; i++) { + + var prop = props[i]; + var bitWiseFound = prop.GetCustomAttributes(true) + .FirstOrDefault(y => y.GetType() == typeof(RegisterAttribute) && ((RegisterAttribute)y).MemoryArea == reg.MemoryAdress); + + if(bitWiseFound != null && reg is NRegister reg16) { + var casted = (RegisterAttribute)bitWiseFound; + var bitIndex = casted.AssignedBitIndex; + + var bytes = BitConverter.GetBytes(reg16.Value); + BitArray bitAr = new BitArray(bytes); + prop.SetValue(collection, bitAr[bitIndex]); + collection.TriggerPropertyChanged(prop.Name); + + } else if (bitWiseFound != null && reg is NRegister reg32) { + var casted = (RegisterAttribute)bitWiseFound; + var bitIndex = casted.AssignedBitIndex; + + var bytes = BitConverter.GetBytes(reg32.Value); + BitArray bitAr = new BitArray(bytes); + prop.SetValue(collection, bitAr[bitIndex]); + collection.TriggerPropertyChanged(prop.Name); + + } + + } + + } + + var foundToUpdate = props.FirstOrDefault(x => x.Name == reg.Name); if (foundToUpdate != null) { @@ -349,27 +390,7 @@ namespace MewtocolNet { } - if (foundToUpdate.PropertyType == typeof(bool) && registerAttr.AssignedBitIndex >= 0) { - - //setting back bit registers to individual properties - if (reg is NRegister shortReg) { - - var bytes = BitConverter.GetBytes(shortReg.Value); - BitArray bitAr = new BitArray(bytes); - foundToUpdate.SetValue(collection, bitAr[registerAttr.AssignedBitIndex]); - - } - - if (reg is NRegister intReg) { - - var bytes = BitConverter.GetBytes(intReg.Value); - BitArray bitAr = new BitArray(bytes); - foundToUpdate.SetValue(collection, bitAr[registerAttr.AssignedBitIndex]); - - } - - - } else if (foundToUpdate.PropertyType == typeof(BitArray)) { + if (foundToUpdate.PropertyType == typeof(BitArray)) { //setting back bit registers if (reg is NRegister shortReg) { @@ -595,6 +616,10 @@ namespace MewtocolNet { } while (stream.DataAvailable); sw.Stop(); + var curCycle = (int)sw.ElapsedMilliseconds; + if (Math.Abs(CycleTimeMs - curCycle) > 2) { + CycleTimeMs = curCycle; + } Logger.Log($"IN MSG ({(int)sw.Elapsed.TotalMilliseconds}ms): {_blockString}", LogLevel.Critical, this); return response.ToString(); } @@ -602,6 +627,7 @@ namespace MewtocolNet { } catch (Exception) { if (IsConnected) { + CycleTimeMs = 0; IsConnected = false; Disconnected?.Invoke(); } diff --git a/MewtocolNet/Mewtocol/MewtocolInterfaceRequests.cs b/MewtocolNet/Mewtocol/MewtocolInterfaceRequests.cs index c71de00..df46dd9 100644 --- a/MewtocolNet/Mewtocol/MewtocolInterfaceRequests.cs +++ b/MewtocolNet/Mewtocol/MewtocolInterfaceRequests.cs @@ -160,7 +160,7 @@ namespace MewtocolNet { var resultBool = result.Response.ParseRCSingleBit(); if(resultBool != null) { - _toRead.LastValue = resultBool.Value; + _toRead.SetValueFromPLC(resultBool.Value); } var finalRes = new BRegisterResult { @@ -216,25 +216,25 @@ namespace MewtocolNet { var resultBytes = result.Response.ParseDTByteString(4).ReverseByteOrder(); var val = short.Parse(resultBytes, NumberStyles.HexNumber); - (_toRead as NRegister).LastValue = val; + _toRead.SetValueFromPLC(val); } else if (numType == typeof(ushort)) { var resultBytes = result.Response.ParseDTByteString(4).ReverseByteOrder(); var val = ushort.Parse(resultBytes, NumberStyles.HexNumber); - (_toRead as NRegister).LastValue = val; + _toRead.SetValueFromPLC(val); } else if (numType == typeof(int)) { var resultBytes = result.Response.ParseDTByteString(8).ReverseByteOrder(); var val = int.Parse(resultBytes, NumberStyles.HexNumber); - (_toRead as NRegister).LastValue = val; + _toRead.SetValueFromPLC(val); } else if (numType == typeof(uint)) { var resultBytes = result.Response.ParseDTByteString(8).ReverseByteOrder(); var val = uint.Parse(resultBytes, NumberStyles.HexNumber); - (_toRead as NRegister).LastValue = val; + _toRead.SetValueFromPLC(val); } else if (numType == typeof(float)) { @@ -245,7 +245,7 @@ namespace MewtocolNet { byte[] floatVals = BitConverter.GetBytes(val); float finalFloat = BitConverter.ToSingle(floatVals, 0); - (_toRead as NRegister).LastValue = finalFloat; + _toRead.SetValueFromPLC(finalFloat); } else if (numType == typeof(TimeSpan)) { @@ -256,7 +256,7 @@ namespace MewtocolNet { var ts = TimeSpan.FromMilliseconds(valMillis); //minmax writable / readable value is 10ms - (_toRead as NRegister).LastValue = ts; + _toRead.SetValueFromPLC(ts); } diff --git a/MewtocolNet/Mewtocol/Subregisters/BRegister.cs b/MewtocolNet/Mewtocol/Subregisters/BRegister.cs index 146e3b0..90d2735 100644 --- a/MewtocolNet/Mewtocol/Subregisters/BRegister.cs +++ b/MewtocolNet/Mewtocol/Subregisters/BRegister.cs @@ -9,8 +9,8 @@ namespace MewtocolNet.Registers { /// public class BRegister : Register { - internal RegisterType RegType { get; set; } - internal SpecialAddress SpecialAddress { get; set; } + internal RegisterType RegType { get; private set; } + internal SpecialAddress SpecialAddress { get; private set; } public bool NeedValue; public bool LastValue; @@ -18,13 +18,7 @@ namespace MewtocolNet.Registers { /// /// The value of the register /// - public bool Value { - get => LastValue; - set { - NeedValue = value; - TriggerChangedEvnt(this); - } - } + public bool Value => LastValue; /// /// Defines a register containing a number @@ -35,8 +29,8 @@ namespace MewtocolNet.Registers { public BRegister (int _address, RegisterType _type = RegisterType.R, string _name = null) { if (_address > 99999) throw new NotSupportedException("Memory adresses cant be greater than 99999"); - MemoryAdress = _address; - Name = _name; + memoryAdress = _address; + name = _name; RegType = _type; @@ -54,7 +48,7 @@ namespace MewtocolNet.Registers { throw new NotSupportedException("Special adress cant be none"); SpecialAddress = _address; - Name = _name; + name = _name; RegType = _type; @@ -74,6 +68,11 @@ namespace MewtocolNet.Registers { } + internal void SetValueFromPLC (bool val) { + LastValue = val; + TriggerChangedEvnt(this); + TriggerNotifyChange(); + } public override string ToString() { return $"Adress: {MemoryAdress} Val: {Value}"; } diff --git a/MewtocolNet/Mewtocol/Subregisters/NRegister.cs b/MewtocolNet/Mewtocol/Subregisters/NRegister.cs index 6381cf6..43618ad 100644 --- a/MewtocolNet/Mewtocol/Subregisters/NRegister.cs +++ b/MewtocolNet/Mewtocol/Subregisters/NRegister.cs @@ -13,13 +13,7 @@ namespace MewtocolNet.Registers { /// /// The value of the register /// - public T Value { - get => LastValue; - set { - NeedValue = value; - TriggerChangedEvnt(this); - } - } + public T Value => LastValue; /// /// Defines a register containing a number @@ -29,21 +23,21 @@ namespace MewtocolNet.Registers { public NRegister(int _adress, string _name = null, bool isBitwise = false) { if (_adress > 99999) throw new NotSupportedException("Memory adresses cant be greater than 99999"); - MemoryAdress = _adress; - Name = _name; + memoryAdress = _adress; + name = _name; Type numType = typeof(T); if (numType == typeof(short)) { - MemoryLength = 0; + memoryLength = 0; } else if (numType == typeof(ushort)) { - MemoryLength = 0; + memoryLength = 0; } else if (numType == typeof(int)) { - MemoryLength = 1; + memoryLength = 1; } else if (numType == typeof(uint)) { - MemoryLength = 1; + memoryLength = 1; } else if (numType == typeof(float)) { - MemoryLength = 1; + memoryLength = 1; } else if (numType == typeof(TimeSpan)) { - MemoryLength = 1; + memoryLength = 1; } else { throw new NotSupportedException($"The type {numType} is not allowed for Number Registers"); } @@ -52,9 +46,16 @@ namespace MewtocolNet.Registers { } + internal void SetValueFromPLC (object val) { + LastValue = (T)val; + TriggerChangedEvnt(this); + TriggerNotifyChange(); + } + public override string ToString() { return $"Adress: {MemoryAdress} Val: {Value}"; } + } diff --git a/MewtocolNet/Mewtocol/Subregisters/Register.cs b/MewtocolNet/Mewtocol/Subregisters/Register.cs index 507491e..61f7a8f 100644 --- a/MewtocolNet/Mewtocol/Subregisters/Register.cs +++ b/MewtocolNet/Mewtocol/Subregisters/Register.cs @@ -17,20 +17,34 @@ namespace MewtocolNet.Registers { /// Gets called whenever the value was changed /// public event Action ValueChanged; + /// + /// Triggers when a property on the register changes + /// public event PropertyChangedEventHandler PropertyChanged; + internal Type collectionType; + /// + /// The type of collection the register is in or null of added manually + /// + public Type CollectionType => collectionType; + + internal string name; /// /// The register name or null of not defined /// - public string Name { get; set; } + public string Name => name; + + internal int memoryAdress; /// /// The registers memory adress if not a special register /// - public int MemoryAdress { get; set; } + public int MemoryAdress => memoryAdress; + + internal int memoryLength; /// /// The rgisters memory length /// - public int MemoryLength { get; set; } + public int MemoryLength => memoryLength; /// /// The value of the register auto converted to a string @@ -42,6 +56,16 @@ namespace MewtocolNet.Registers { /// public string RegisterPLCName => GetRegisterPLCName(); + /// + /// The combined name with the holding register class type infront + /// + public string CombinedName => GetCombinedName(); + + /// + /// The name of the class that contains this register or empty if it was added manually + /// + public string ContainerName => GetContainerName(); + internal bool isUsedBitwise { get; set; } internal Register () { @@ -174,7 +198,19 @@ namespace MewtocolNet.Registers { } - public string GetRegisterPLCName () { + internal string GetCombinedName () { + + return $"{(CollectionType != null ? $"{CollectionType.Name}." : "")}{Name ?? "Unnamed"}"; + + } + + internal string GetContainerName () { + + return $"{(CollectionType != null ? $"{CollectionType.Name}" : "")}"; + + } + + internal string GetRegisterPLCName () { return $"{GetRegisterString()}{MemoryAdress}"; diff --git a/MewtocolNet/Mewtocol/Subregisters/SRegister.cs b/MewtocolNet/Mewtocol/Subregisters/SRegister.cs index 9414caa..89d2742 100644 --- a/MewtocolNet/Mewtocol/Subregisters/SRegister.cs +++ b/MewtocolNet/Mewtocol/Subregisters/SRegister.cs @@ -8,11 +8,8 @@ namespace MewtocolNet.Registers { public class SRegister : Register { private string lastVal = ""; - public string Value { - get => lastVal; - - } + public string Value => lastVal; public short ReservedSize { get; set; } @@ -22,8 +19,8 @@ namespace MewtocolNet.Registers { public SRegister(int _adress, int _reservedStringSize, string _name = null) { if (_adress > 99999) throw new NotSupportedException("Memory adresses cant be greater than 99999"); - Name = _name; - MemoryAdress = _adress; + name = _name; + memoryAdress = _adress; ReservedSize = (short)_reservedStringSize; //calc mem length @@ -32,7 +29,7 @@ namespace MewtocolNet.Registers { wordsize++; } - MemoryLength = (int)Math.Round(wordsize + 1); + memoryLength = (int)Math.Round(wordsize + 1); } public override string ToString() { @@ -62,7 +59,7 @@ namespace MewtocolNet.Registers { return asciistring.ToString(); } - public void SetValueFromPLC (string val) { + internal void SetValueFromPLC (string val) { lastVal = val; TriggerChangedEvnt(this); TriggerNotifyChange(); diff --git a/MewtocolNet/MewtocolNet.csproj b/MewtocolNet/MewtocolNet.csproj index aac7806..3d7cbed 100644 --- a/MewtocolNet/MewtocolNet.csproj +++ b/MewtocolNet/MewtocolNet.csproj @@ -2,7 +2,7 @@ netstandard2.0 MewtocolNet - 0.3.4 + 0.3.5 Felix Weiss Womed true