Fixed bug a bug where the writeregister method always returned false

- fixed a bug where the adress ToString of a register with a special adress was always ending with 0
- counted up version
This commit is contained in:
Felix Weiß
2022-06-23 12:15:42 +02:00
parent 4c719843f2
commit 83f17a4eae
6 changed files with 31 additions and 16 deletions

View File

@@ -2,6 +2,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using MewtocolNet; using MewtocolNet;
using MewtocolNet.Logging; using MewtocolNet.Logging;
using MewtocolNet.Registers;
namespace Examples { namespace Examples {

View File

@@ -278,18 +278,13 @@ namespace MewtocolNet {
//read number as bit array by invdividual properties //read number as bit array by invdividual properties
if (prop.PropertyType == typeof(bool) && cAttribute.AssignedBitIndex != -1) { if (prop.PropertyType == typeof(bool) && cAttribute.AssignedBitIndex != -1) {
if (cAttribute.BitCount == BitCount.B16) { //var bitwiseCount = Registers.Count(x => x.Value.isUsedBitwise);
AddRegister<short>(collection.GetType(), cAttribute.MemoryArea, _name: propName, _isBitwise: true);
} else {
AddRegister<int>(collection.GetType(), cAttribute.MemoryArea, _name: propName, _isBitwise: true);
}
//attach for bools to be read when bitregister if (cAttribute.BitCount == BitCount.B16) {
//RegisterChanged += (reg) => { AddRegister<short>(collection.GetType(), cAttribute.MemoryArea, _name: $"Auto_Bitwise_DT{cAttribute.MemoryArea}", _isBitwise: true);
// if (reg.Name == propName) { } else {
// prop.SetValue() AddRegister<int>(collection.GetType(), cAttribute.MemoryArea, _name: $"Auto_Bitwise_DDT{cAttribute.MemoryArea}", _isBitwise: true);
// } }
//};
} }

View File

@@ -183,7 +183,7 @@ namespace MewtocolNet {
var result = await SendCommandAsync(requeststring); 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 @@ namespace MewtocolNet {
var result = await SendCommandAsync(requeststring); 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 @@ namespace MewtocolNet {
var result = await SendCommandAsync(requeststring); var result = await SendCommandAsync(requeststring);
return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}#WD"); return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}$WD");
} }
#endregion #endregion

View File

@@ -1,4 +1,6 @@
namespace MewtocolNet.Registers { using System;
namespace MewtocolNet.Registers {
/// <summary> /// <summary>
/// Result for a read/write operation /// Result for a read/write operation
/// </summary> /// </summary>
@@ -11,6 +13,19 @@
string errmsg = Result.Success ? "" : $", Error [{Result.ErrorDescription}]"; string errmsg = Result.Success ? "" : $", Error [{Result.ErrorDescription}]";
return $"Result [{Result.Success}], Register [{Register.ToString()}]{errmsg}"; return $"Result [{Result.Success}], Register [{Register.ToString()}]{errmsg}";
} }
/// <summary>
/// Trys to get the value of there is one
/// </summary>
public bool TryGetValue (out T value) {
if(Result.Success) {
value = Register.Value;
return true;
}
value = default(T);
return false;
}
} }

View File

@@ -212,6 +212,10 @@ namespace MewtocolNet.Registers {
internal string GetRegisterPLCName () { internal string GetRegisterPLCName () {
if (this is BRegister bReg && bReg.SpecialAddress != SpecialAddress.None) {
return $"{GetRegisterString()}{bReg.SpecialAddress}";
}
return $"{GetRegisterString()}{MemoryAdress}"; return $"{GetRegisterString()}{MemoryAdress}";
} }

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<PackageId>MewtocolNet</PackageId> <PackageId>MewtocolNet</PackageId>
<Version>0.3.5</Version> <Version>0.3.6</Version>
<Authors>Felix Weiss</Authors> <Authors>Felix Weiss</Authors>
<Company>Womed</Company> <Company>Womed</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>