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}"/> + + + + + +