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

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

View File

@@ -1,4 +1,6 @@
namespace MewtocolNet.Registers {
using System;
namespace MewtocolNet.Registers {
/// <summary>
/// Result for a read/write operation
/// </summary>
@@ -11,6 +13,19 @@
string errmsg = Result.Success ? "" : $", Error [{Result.ErrorDescription}]";
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 () {
if (this is BRegister bReg && bReg.SpecialAddress != SpecialAddress.None) {
return $"{GetRegisterString()}{bReg.SpecialAddress}";
}
return $"{GetRegisterString()}{MemoryAdress}";
}