From 4fb9910d549e7767b3765d7c662f81d47d268c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Wei=C3=9F?= <72068105+Sandoun@users.noreply.github.com> Date: Sun, 13 Aug 2023 23:31:34 +0200 Subject: [PATCH] Adjusted for new mewtocol ver --- Examples.WPF/Examples.WPF.csproj | 4 +- .../TestRegisterCollection.cs | 3 + Examples.WPF/Views/ConnectView.xaml.cs | 36 ++++- Examples.WPF/Views/PlcDataView.xaml | 60 +++++++- MewtocolNet/CustomTypes/DateAndTime.cs | 92 ++++++++++++ MewtocolNet/Helpers/ParsedPlcName.cs | 3 + MewtocolNet/IPlc.cs | 18 ++- MewtocolNet/Logging/Logger.cs | 4 +- MewtocolNet/Mewtocol.cs | 14 +- MewtocolNet/MewtocolInterface.cs | 63 +++++--- .../MewtocolInterfaceRegisterHandling.cs | 32 ++-- MewtocolNet/MewtocolNet.csproj | 11 +- MewtocolNet/PublicEnums/OPMode.cs | 16 +- .../RegisterAttributes/RegisterCollection.cs | 3 +- MewtocolNet/RegisterBuilding/AddressTools.cs | 4 +- .../BuilderPatterns/RBuild.cs | 114 +++----------- .../BuilderPatterns/RBuildAnon.cs | 130 ++++++++++++++++ .../BuilderPatterns/RBuildMulti.cs | 142 ++++++++++++++++++ MewtocolNet/Registers/Base/IRegister.cs | 6 + MewtocolNet/Registers/Base/Register.cs | 3 + .../Registers/Classes/StringRegister.cs | 2 +- MewtocolNet/TypeConversion/Conversions.cs | 9 ++ .../UnderlyingRegisters/Areas/AreaBase.cs | 58 ++++++- .../UnderlyingRegisters/Areas/IMemoryArea.cs | 12 +- .../UnderlyingRegisters/MemoryAreaManager.cs | 16 +- nuget.config | 9 ++ 26 files changed, 696 insertions(+), 168 deletions(-) create mode 100644 MewtocolNet/CustomTypes/DateAndTime.cs create mode 100644 MewtocolNet/RegisterBuilding/BuilderPatterns/RBuildAnon.cs create mode 100644 MewtocolNet/RegisterBuilding/BuilderPatterns/RBuildMulti.cs create mode 100644 nuget.config diff --git a/Examples.WPF/Examples.WPF.csproj b/Examples.WPF/Examples.WPF.csproj index c9992de..fb8c0a6 100644 --- a/Examples.WPF/Examples.WPF.csproj +++ b/Examples.WPF/Examples.WPF.csproj @@ -8,7 +8,7 @@ - + - + diff --git a/Examples.WPF/RegisterCollections/TestRegisterCollection.cs b/Examples.WPF/RegisterCollections/TestRegisterCollection.cs index 4ea16b7..df74e3f 100644 --- a/Examples.WPF/RegisterCollections/TestRegisterCollection.cs +++ b/Examples.WPF/RegisterCollections/TestRegisterCollection.cs @@ -19,6 +19,9 @@ public class TestRegisterCollection : RegisterCollection { [Register("R16B")] public bool TestR16B { get; set; } + [Register("R902")] + public bool Test { get; set; } + [BitRegister("DT1000", 0), PollLevel(3)] public bool? TestDT100_Word_Duplicate_SingleBit { get; set; } diff --git a/Examples.WPF/Views/ConnectView.xaml.cs b/Examples.WPF/Views/ConnectView.xaml.cs index b438b2c..b83915c 100644 --- a/Examples.WPF/Views/ConnectView.xaml.cs +++ b/Examples.WPF/Views/ConnectView.xaml.cs @@ -2,6 +2,7 @@ using Examples.WPF.ViewModels; using MewtocolNet; using MewtocolNet.ComCassette; +using MewtocolNet.Logging; using MewtocolNet.Registers; using System; using System.Collections.Generic; @@ -106,25 +107,44 @@ public partial class ConnectView : UserControl { b.Struct("DDT1016").PollLevel(2).Build(); b.Struct("DDT1018").PollLevel(2).Build(); - b.String("DT1024", 32).PollLevel(3).Build(); - b.String("DT1042", 5).PollLevel(4).Build(); + b.Struct("DDT1020").PollLevel(2).Build(); + b.Struct("DDT1022").PollLevel(2).Build(); + + b.String("DT1028", 32).PollLevel(3).Build(); + b.String("DT1046", 5).PollLevel(4).Build(); + + b.Struct("DT1000").AsArray(5).PollLevel(1).Build(); }) - .WithHeartbeatTask(async () => { + .WithHeartbeatTask(async (plc) => { - await heartbeatSetter.WriteAsync((short)new Random().Next(short.MinValue, short.MaxValue)); + var randShort = (short)new Random().Next(short.MinValue, short.MaxValue); - if (outputContactReference.Value != null) - await outputContactReference.WriteAsync(!outputContactReference.Value.Value); + //write direct + //await heartbeatSetter.WriteAsync(randShort); + //or by anonymous + await plc.Register.Struct("DT1000").WriteAsync(randShort); - if(testBoolReference.Value != null) + //write a register without a reference + bool randBool = new Random().Next(0, 2) == 1; + await plc.Register.Bool("Y4").WriteAsync(randBool); + + if (testBoolReference.Value != null) await testBoolReference.WriteAsync(!testBoolReference.Value.Value); + await plc.Register.Struct("DDT1022").WriteAsync(DateAndTime.FromDateTime(DateTime.UtcNow)); + }) .Build(); //connect to it - await App.ViewModel.Plc.ConnectAsync(); + await App.ViewModel.Plc.ConnectAsync(async () => { + + await App.ViewModel.Plc.RestartProgramAsync(); + + }); + + await App.ViewModel.Plc.AwaitFirstDataCycleAsync(); if (App.ViewModel.Plc.IsConnected) { diff --git a/Examples.WPF/Views/PlcDataView.xaml b/Examples.WPF/Views/PlcDataView.xaml index d3951c0..8df66b1 100644 --- a/Examples.WPF/Views/PlcDataView.xaml +++ b/Examples.WPF/Views/PlcDataView.xaml @@ -49,6 +49,21 @@ Fill="Lime" IsEnabled="{Binding Plc.IsConnected}"/> + + + + + +