diff --git a/Examples/Program.cs b/Examples/Program.cs index 4c516d0..fa9e26e 100644 --- a/Examples/Program.cs +++ b/Examples/Program.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using MewtocolNet; using MewtocolNet.Logging; +using MewtocolNet.Registers; namespace Examples { diff --git a/MewtocolNet/Mewtocol/MewtocolInterface.cs b/MewtocolNet/Mewtocol/MewtocolInterface.cs index 51384e8..51dcd2d 100644 --- a/MewtocolNet/Mewtocol/MewtocolInterface.cs +++ b/MewtocolNet/Mewtocol/MewtocolInterface.cs @@ -278,19 +278,14 @@ public MewtocolInterface WithRegisterCollection (RegisterCollectionBase collecti //read number as bit array by invdividual properties if (prop.PropertyType == typeof(bool) && cAttribute.AssignedBitIndex != -1) { + //var bitwiseCount = Registers.Count(x => x.Value.isUsedBitwise); + if (cAttribute.BitCount == BitCount.B16) { - AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: propName, _isBitwise: true); + AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: $"Auto_Bitwise_DT{cAttribute.MemoryArea}", _isBitwise: true); } else { - AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: propName, _isBitwise: true); + AddRegister(collection.GetType(), cAttribute.MemoryArea, _name: $"Auto_Bitwise_DDT{cAttribute.MemoryArea}", _isBitwise: true); } - //attach for bools to be read when bitregister - //RegisterChanged += (reg) => { - // if (reg.Name == propName) { - // prop.SetValue() - // } - //}; - } if (prop.PropertyType == typeof(TimeSpan)) { diff --git a/MewtocolNet/Mewtocol/MewtocolInterfaceRequests.cs b/MewtocolNet/Mewtocol/MewtocolInterfaceRequests.cs index df46dd9..01e8a3d 100644 --- a/MewtocolNet/Mewtocol/MewtocolInterfaceRequests.cs +++ b/MewtocolNet/Mewtocol/MewtocolInterfaceRequests.cs @@ -183,7 +183,7 @@ public async Task WriteBoolRegister (BRegister _toWrite, bool value) { var result = await SendCommandAsync(requeststring); - return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}#WC"); + return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}$WC"); } @@ -313,7 +313,7 @@ public async Task WriteNumRegister (NRegister _toWrite, T _value) { var result = await SendCommandAsync(requeststring); - return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}#WD"); + return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}$WD"); } @@ -369,7 +369,7 @@ public async Task WriteStringRegister(SRegister _toWrite, string _value, i var result = await SendCommandAsync(requeststring); - return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}#WD"); + return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}$WD"); } #endregion diff --git a/MewtocolNet/Mewtocol/Subregisters/NRegisterResult.cs b/MewtocolNet/Mewtocol/Subregisters/NRegisterResult.cs index 66b381c..79169df 100644 --- a/MewtocolNet/Mewtocol/Subregisters/NRegisterResult.cs +++ b/MewtocolNet/Mewtocol/Subregisters/NRegisterResult.cs @@ -1,4 +1,6 @@ -namespace MewtocolNet.Registers { +using System; + +namespace MewtocolNet.Registers { /// /// Result for a read/write operation /// @@ -11,6 +13,19 @@ public override string ToString() { string errmsg = Result.Success ? "" : $", Error [{Result.ErrorDescription}]"; return $"Result [{Result.Success}], Register [{Register.ToString()}]{errmsg}"; } + + /// + /// Trys to get the value of there is one + /// + public bool TryGetValue (out T value) { + if(Result.Success) { + value = Register.Value; + return true; + } + value = default(T); + return false; + } + } diff --git a/MewtocolNet/Mewtocol/Subregisters/Register.cs b/MewtocolNet/Mewtocol/Subregisters/Register.cs index 61f7a8f..a1d0bf9 100644 --- a/MewtocolNet/Mewtocol/Subregisters/Register.cs +++ b/MewtocolNet/Mewtocol/Subregisters/Register.cs @@ -212,6 +212,10 @@ internal string GetContainerName () { internal string GetRegisterPLCName () { + if (this is BRegister bReg && bReg.SpecialAddress != SpecialAddress.None) { + return $"{GetRegisterString()}{bReg.SpecialAddress}"; + } + return $"{GetRegisterString()}{MemoryAdress}"; } diff --git a/MewtocolNet/MewtocolNet.csproj b/MewtocolNet/MewtocolNet.csproj index 3d7cbed..560c60b 100644 --- a/MewtocolNet/MewtocolNet.csproj +++ b/MewtocolNet/MewtocolNet.csproj @@ -2,7 +2,7 @@ netstandard2.0 MewtocolNet - 0.3.5 + 0.3.6 Felix Weiss Womed true