Move examples from root to /Examples

This commit is contained in:
Felix Weiß
2023-08-21 16:21:55 +02:00
parent 47e50078b0
commit 993c3cba7e
26 changed files with 91 additions and 81 deletions

View File

@@ -0,0 +1,40 @@
using Examples.WPF.RegisterCollections;
using MewtocolNet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Examples.WPF.ViewModels {
public class AppViewModel : ViewModelBase {
private IPlc? plc;
private TestRegisterCollection testRegCollection = null!;
public bool PlcIsNull => plc == null;
public bool PlcIsNotNull => plc != null;
public IPlc? Plc {
get => plc;
set {
plc = value;
OnPropChange();
OnPropChange(nameof(PlcIsNull));
OnPropChange(nameof(PlcIsNotNull));
}
}
public TestRegisterCollection TestRegCollection {
get => testRegCollection;
set {
testRegCollection = value;
OnPropChange();
}
}
}
}

View File

@@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.Configuration.Internal;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Threading;
using MewtocolNet;
using MewtocolNet.ComCassette;
namespace Examples.WPF.ViewModels;
internal class ConnectViewViewModel : ViewModelBase {
private bool hasComports = false;
private IEnumerable<int> baudRates = null!;
private IEnumerable<string> comPorts = null!;
private IEnumerable<CassetteInformation> foundCassettes = null!;
private string selectedIP = "192.168.115.210";
private string selectedPort = "9094";
private bool isConnecting;
public IEnumerable<int> BaudRates {
get => baudRates;
set {
baudRates = value;
OnPropChange();
}
}
public IEnumerable<string> ComPorts {
get => comPorts;
set {
comPorts = value;
OnPropChange();
}
}
public IEnumerable<CassetteInformation> FoundCassettes {
get => foundCassettes;
set {
foundCassettes = value;
OnPropChange();
}
}
public bool HasComports {
get => hasComports;
set {
hasComports = value;
OnPropChange();
}
}
public string SelectedIP {
get { return selectedIP; }
set {
selectedIP = value;
OnPropChange();
}
}
public string SelectedPort {
get { return selectedPort; }
set {
selectedPort = value;
OnPropChange();
}
}
public bool IsConnecting {
get { return isConnecting; }
set {
isConnecting = value;
OnPropChange();
}
}
private DispatcherTimer tm;
public ConnectViewViewModel() {
BaudRates = Mewtocol.GetUseableBaudRates();
ScanTimerTick(null, null!);
tm = new DispatcherTimer {
Interval = TimeSpan.FromSeconds(3),
};
tm.Tick += ScanTimerTick;
tm.Start();
}
private async void ScanTimerTick(object? sender, EventArgs e) {
ComPorts = Mewtocol.GetSerialPortNames();
HasComports = ComPorts != null && ComPorts.Count() > 0;
var found = await CassetteFinder.FindClientsAsync(timeoutMs: 1000);
if (FoundCassettes == null || !Enumerable.SequenceEqual(found, FoundCassettes))
FoundCassettes = found;
}
internal void SelectedCassette (CassetteInformation cassette) {
SelectedIP = cassette.IPAddress.ToString();
SelectedPort = cassette.Port.ToString();
}
internal void EndTimer() => tm.Stop();
}

View File

@@ -0,0 +1,36 @@
using Examples.WPF.RegisterCollections;
using MewtocolNet;
using MewtocolNet.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Examples.WPF.ViewModels;
public class PlcDataViewViewModel : ViewModelBase {
private ReconnectArgs plcCurrentReconnectArgs = null!;
public IPlc Plc => App.ViewModel.Plc!;
public TestRegisterCollection RegCollection => App.ViewModel.TestRegCollection;
public ReconnectArgs PlcCurrentReconnectArgs {
get => plcCurrentReconnectArgs;
set {
plcCurrentReconnectArgs = value;
OnPropChange();
}
}
public PlcDataViewViewModel () {
Plc.ReconnectTryStarted += (s, e) => PlcCurrentReconnectArgs = e;
Plc.Reconnected += (s, e) => PlcCurrentReconnectArgs = null!;
Plc.Disconnected += (s, e) => PlcCurrentReconnectArgs = null!;
}
}

View File

@@ -0,0 +1,18 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Examples.WPF.ViewModels;
public abstract class ViewModelBase : INotifyPropertyChanged {
public event PropertyChangedEventHandler? PropertyChanged;
public void PropChange(string _name) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(_name));
}
protected void OnPropChange([CallerMemberName] string propertyName = null) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}