mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 03:01:24 +00:00
Update README.md
This commit is contained in:
56
README.md
56
README.md
@@ -85,28 +85,15 @@ Logger.OnNewLogMessage((date, msg) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//setting up a new PLC interface
|
//setting up a new PLC interface
|
||||||
MewtocolInterface interf = new MewtocolInterface("192.168.115.5");
|
MewtocolInterface plc = new MewtocolInterface("192.168.115.5");
|
||||||
|
|
||||||
await interf.ConnectAsync();
|
await plc.ConnectAsync();
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also use the callbacks of the `ConnectAsync()` method to do something after the initial connection establishment.
|
|
||||||
|
|
||||||
```C#
|
|
||||||
await interf.ConnectAsync(
|
|
||||||
//PLC connected
|
|
||||||
(plc) => {
|
|
||||||
if(plcinf.OperationMode.RunMode)
|
|
||||||
Console.WriteLine("PLC is in RUN");
|
|
||||||
},
|
|
||||||
//Connection failed
|
|
||||||
() => {
|
|
||||||
Console.WriteLine("PLC failed to connect");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
```
|
|
||||||
## Reading data registers / contacts
|
## Reading data registers / contacts
|
||||||
|
|
||||||
|
[Detailed instructions](/wiki/Attribute-handled-reading)
|
||||||
|
|
||||||
- Create a new class that inherits from `RegisterCollectionBase`
|
- Create a new class that inherits from `RegisterCollectionBase`
|
||||||
|
|
||||||
```C#
|
```C#
|
||||||
@@ -136,20 +123,14 @@ public class TestRegisters : RegisterCollectionBase {
|
|||||||
- attach an automatic poller by chaining `.WithPoller()` after the register attachment
|
- attach an automatic poller by chaining `.WithPoller()` after the register attachment
|
||||||
|
|
||||||
```C#
|
```C#
|
||||||
//attaching a logger
|
|
||||||
Logger.LogLevel = LogLevel.Verbose;
|
|
||||||
Logger.OnNewLogMessage((date, msg) => {
|
|
||||||
Console.WriteLine($"{date.ToString("HH:mm:ss")} {msg}");
|
|
||||||
});
|
|
||||||
|
|
||||||
//setting up a new PLC interface and register collection
|
//setting up a new PLC interface and register collection
|
||||||
MewtocolInterface interf = new MewtocolInterface("192.168.115.5");
|
MewtocolInterface plc = new MewtocolInterface("192.168.115.5");
|
||||||
TestRegisters registers = new TestRegisters();
|
TestRegisters registers = new TestRegisters();
|
||||||
|
|
||||||
//attaching the register collection and an automatic poller
|
//attaching the register collection and an automatic poller
|
||||||
interf.WithRegisterCollection(registers).WithPoller();
|
plc.WithRegisterCollection(registers).WithPoller();
|
||||||
|
|
||||||
await interf.ConnectAsync(
|
await plc.ConnectAsync(
|
||||||
(plcinf) => {
|
(plcinf) => {
|
||||||
//reading a value from the register collection
|
//reading a value from the register collection
|
||||||
Console.WriteLine($"Time Value is: {registers.TestTime}");
|
Console.WriteLine($"Time Value is: {registers.TestTime}");
|
||||||
@@ -170,37 +151,28 @@ Sets the register without feedback if it was set
|
|||||||
|
|
||||||
```C#
|
```C#
|
||||||
//inverts the boolean register
|
//inverts the boolean register
|
||||||
interf.SetRegister(nameof(registers.TestBool1), !registers.TestBool1);
|
plc.SetRegister(nameof(registers.TestBool1), !registers.TestBool1);
|
||||||
|
|
||||||
//set the current second to the PLCs TIME register
|
//set the current second to the PLCs TIME register
|
||||||
interf.SetRegister(nameof(registers.TestTime), TimeSpan.FromSeconds(DateTime.Now.Second));
|
plc.SetRegister(nameof(registers.TestTime), TimeSpan.FromSeconds(DateTime.Now.Second));
|
||||||
|
|
||||||
//writes 'Test' to the PLCs string register
|
//writes 'Test' to the PLCs string register
|
||||||
interf.SetRegister(nameof(registers.TestString1), "Test");
|
plc.SetRegister(nameof(registers.TestString1), "Test");
|
||||||
```
|
```
|
||||||
|
|
||||||
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)
|
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
|
Adding registers to a manual list
|
||||||
```C#
|
```C#
|
||||||
interf.AddRegister<bool>(105, _name: "ManualBoolRegister");
|
plc.AddRegister<bool>(105, _name: "ManualBoolRegister");
|
||||||
```
|
```
|
||||||
|
|
||||||
Reading the value of the manually added register
|
Reading the value of the manually added register
|
||||||
```C#
|
```C#
|
||||||
//get the value as a string
|
//get the value as a string
|
||||||
string value = interf.GetRegister("ManualBoolRegister").GetValueString();
|
string value = plc.GetRegister("ManualBoolRegister").GetValueString();
|
||||||
//get the value by casting
|
//get the value by casting
|
||||||
bool value2 = interf.GetRegister<BRegister>("ManualBoolRegister").Value;
|
bool value2 = plc.GetRegister<BRegister>("ManualBoolRegister").Value;
|
||||||
//for double casted ones like numbers
|
//for double casted ones like numbers
|
||||||
var value2 = interf.GetRegister<NRegister<short>>("NumberRegister").Value;
|
var value2 = plc.GetRegister<NRegister<short>>("NumberRegister").Value;
|
||||||
```
|
|
||||||
|
|
||||||
### Asynchronous
|
|
||||||
|
|
||||||
Sets the register waiting for the PLC to confirm it was set
|
|
||||||
|
|
||||||
```C#
|
|
||||||
//inverts the boolean register
|
|
||||||
await interf.SetRegisterAsync(nameof(registers.TestBool1), !registers.TestBool1);
|
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user