mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 03:01:24 +00:00
Added auto prop sending
- updated readme
This commit is contained in:
@@ -164,9 +164,19 @@ public class ExampleScenarios {
|
||||
|
||||
await interf.ConnectAsync();
|
||||
|
||||
await interf.SetRegisterAsync(nameof(registers.StartCyclePLC), true);
|
||||
//use the async method to make sure the cycling is stopped
|
||||
await interf.SetRegisterAsync(nameof(registers.StartCyclePLC), false);
|
||||
|
||||
await Task.Delay(-1);
|
||||
await Task.Delay(5000);
|
||||
|
||||
//set the register without waiting for it async
|
||||
registers.StartCyclePLC = true;
|
||||
|
||||
await Task.Delay(5000);
|
||||
|
||||
registers.StartCyclePLC = false;
|
||||
|
||||
await Task.Delay(2000);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MewtocolNet.Logging;
|
||||
using MewtocolNet.RegisterAttributes;
|
||||
using MewtocolNet.Registers;
|
||||
|
||||
namespace MewtocolNet {
|
||||
@@ -194,6 +195,12 @@ namespace MewtocolNet {
|
||||
|
||||
}
|
||||
|
||||
internal void PropertyRegisterWasSet (string propName, object value) {
|
||||
|
||||
SetRegister(propName, value);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Register Adding
|
||||
|
||||
@@ -38,7 +38,9 @@ namespace MewtocolNet.RegisterAttributes
|
||||
/// <summary>
|
||||
/// Use this on the setter method of a property to enable automatic property register writing
|
||||
/// </summary>
|
||||
public static void AutoSetter<T> (object value, ref T privateField) {
|
||||
public void AutoSetter<T> (object value, ref T privateField, [CallerMemberName] string propName = null) {
|
||||
|
||||
PLCInterface.PropertyRegisterWasSet(propName, value);
|
||||
|
||||
if(value is IRegister reg) {
|
||||
|
||||
|
||||
26
README.md
26
README.md
@@ -143,10 +143,29 @@ await plc.ConnectAsync(
|
||||
|
||||
⚠ **Never set a register by setting the property, always use one of the provided methods**
|
||||
|
||||
Registers are stored in an underlying layer for automatic handling, each register has a unique name and address.
|
||||
|
||||
Classes that derive from `RegisterCollectionBase` reference these registers automatically using attributes.
|
||||
All the heavy lifting is done automatically for you, setting this up is described [here](https://github.com/WOmed/MewtocolNet/wiki/Attribute-handled-reading)
|
||||
|
||||
### Asynchronous
|
||||
|
||||
This operations awaits a task to make sure the register was actually set to your desired value before progressing
|
||||
|
||||
```C#
|
||||
//sets the register to false
|
||||
await plc.SetRegisterAsync(nameof(registers.TestBool1), false);
|
||||
|
||||
//set the current second to the PLCs TIME register
|
||||
await plc.SetRegisterAsync(nameof(registers.TestTime), TimeSpan.FromSeconds(DateTime.Now.Second));
|
||||
```
|
||||
|
||||
### Synchronous
|
||||
|
||||
Sets the register without feedback if it was set
|
||||
|
||||
You can use the method to set a register
|
||||
|
||||
```C#
|
||||
//inverts the boolean register
|
||||
plc.SetRegister(nameof(registers.TestBool1), !registers.TestBool1);
|
||||
@@ -158,6 +177,13 @@ plc.SetRegister(nameof(registers.TestTime), TimeSpan.FromSeconds(DateTime.Now.Se
|
||||
plc.SetRegister(nameof(registers.TestString1), "Test");
|
||||
```
|
||||
|
||||
or write to a register in your `RegisterCollectionBase` directly (you need to attach a register collection to your interface beforehand)
|
||||
|
||||
```C#
|
||||
//inverts the boolean register
|
||||
registers.TestBool1 = true;
|
||||
```
|
||||
|
||||
You can also set a register by calling its name directly (Must be either in an attached register collection or added to the list manually)
|
||||
|
||||
Adding registers to a manual list
|
||||
|
||||
Reference in New Issue
Block a user