Skip to content

Commit

Permalink
Fixed bug a bug where the writeregister method always returned false
Browse files Browse the repository at this point in the history
- fixed a bug where the adress ToString of a register with a special adress was always ending with 0
- counted up version
  • Loading branch information
Sandoun committed Jun 23, 2022
1 parent 4c71984 commit 83f17a4
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using MewtocolNet;
using MewtocolNet.Logging;
using MewtocolNet.Registers;

namespace Examples {

Expand Down
13 changes: 4 additions & 9 deletions MewtocolNet/Mewtocol/MewtocolInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<short>(collection.GetType(), cAttribute.MemoryArea, _name: propName, _isBitwise: true);
AddRegister<short>(collection.GetType(), cAttribute.MemoryArea, _name: $"Auto_Bitwise_DT{cAttribute.MemoryArea}", _isBitwise: true);
} else {
AddRegister<int>(collection.GetType(), cAttribute.MemoryArea, _name: propName, _isBitwise: true);
AddRegister<int>(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)) {
Expand Down
6 changes: 3 additions & 3 deletions MewtocolNet/Mewtocol/MewtocolInterfaceRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public async Task<bool> 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");

}

Expand Down Expand Up @@ -313,7 +313,7 @@ public async Task<bool> WriteNumRegister<T> (NRegister<T> _toWrite, T _value) {

var result = await SendCommandAsync(requeststring);

return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}#WD");
return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}$WD");

}

Expand Down Expand Up @@ -369,7 +369,7 @@ public async Task<bool> 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
Expand Down
17 changes: 16 additions & 1 deletion MewtocolNet/Mewtocol/Subregisters/NRegisterResult.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MewtocolNet.Registers {
using System;

namespace MewtocolNet.Registers {
/// <summary>
/// Result for a read/write operation
/// </summary>
Expand All @@ -11,6 +13,19 @@ public override string ToString() {
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;
}

}


Expand Down
4 changes: 4 additions & 0 deletions MewtocolNet/Mewtocol/Subregisters/Register.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";

}
Expand Down
2 changes: 1 addition & 1 deletion MewtocolNet/MewtocolNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>MewtocolNet</PackageId>
<Version>0.3.5</Version>
<Version>0.3.6</Version>
<Authors>Felix Weiss</Authors>
<Company>Womed</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down

0 comments on commit 83f17a4

Please sign in to comment.