aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs47
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MonitoringViewVM.cs93
2 files changed, 140 insertions, 0 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs
new file mode 100644
index 000000000..83eee1333
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+using Tango.Integration.Observables;
+
+namespace Tango.MachineStudio.Developer.ViewModels
+{
+ public class IOVM : ExtendedObject
+ {
+ private Io _io;
+ public Io IO
+ {
+ get { return _io; }
+ set { _io = value; RaisePropertyChangedAuto(); }
+ }
+
+ private String _name;
+ public String Name
+ {
+ get { return _name; }
+ set { _name = value; }
+ }
+
+ private bool _index;
+ public bool Index
+ {
+ get { return _index; }
+ set { _index = value; }
+ }
+
+ private double _value;
+ public double Value
+ {
+ get { return _value; }
+ set { _value = value; RaisePropertyChanged(nameof(Value)); }
+ }
+
+ public IOVM(Io io, String name)
+ {
+ IO = io;
+ Name = name;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MonitoringViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MonitoringViewVM.cs
new file mode 100644
index 000000000..8edbd7b83
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MonitoringViewVM.cs
@@ -0,0 +1,93 @@
+using Google.Protobuf.Collections;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Integration.Observables;
+using Tango.Integration.Services;
+using Tango.MachineStudio.Common.StudioApplication;
+using Tango.PMR.Diagnostics;
+using Tango.SharedUI;
+
+namespace Tango.MachineStudio.Developer.ViewModels
+{
+ public class MonitoringViewVM : ViewModel
+ {
+ private ObservableCollection<IOVM> _availableControllers;
+ public ObservableCollection<IOVM> AvailableControllers
+ {
+ get { return _availableControllers; }
+ set { _availableControllers = value; }
+ }
+
+ private ObservableCollection<IOVM> _controllers;
+ public ObservableCollection<IOVM> Controllers
+ {
+ get { return _controllers; }
+ set { _controllers = value; }
+ }
+
+ private ObservablesEntitiesAdapter _adapter;
+ public ObservablesEntitiesAdapter Adapter
+ {
+ get { return _adapter; }
+ set { _adapter = value; }
+ }
+
+ public IStudioApplicationManager ApplicationManager { get; set; }
+
+ public MonitoringViewVM(IStudioApplicationManager applicationManager)
+ {
+ ApplicationManager = applicationManager;
+ ApplicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged;
+
+ if (!this.DesignMode)
+ {
+ Adapter = ObservablesEntitiesAdapter.Instance;
+ AvailableControllers = Adapter.Ios.Select(x => new IOVM(x, x.Name)).ToObservableCollection();
+ }
+
+ Controllers = new ObservableCollection<IOVM>();
+ }
+
+ private void ApplicationManager_ConnectedMachineChanged(object sender, IExternalBridgeClient machine)
+ {
+ if (machine != null)
+ {
+ machine.DiagnosticsDataAvailable -= Machine_DiagnosticsDataAvailable;
+ machine.DiagnosticsDataAvailable += Machine_DiagnosticsDataAvailable;
+ }
+ }
+
+ private void Machine_DiagnosticsDataAvailable(object sender, PushDiagnosticsResponse data)
+ {
+ foreach (var prop in data.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
+ {
+ IOVM controller = _controllers.SingleOrDefault(x => x.IO.Name == prop.Name);
+
+ if (controller != null)
+ {
+ if (!controller.IO.MultiChannel)
+ {
+ RepeatedField<double> arr = prop.GetValue(data) as RepeatedField<double>;
+ controller.Value = arr.Last();
+ }
+ else
+ {
+ //DoubleArray[] arrayOfDoubles = Enumerable.ToArray(prop.GetValue(data) as IEnumerable<DoubleArray>);
+ //(controller as GraphMultiController).PushData(arrayOfDoubles.Select(x => x.Data.ToList()).ToList());
+ }
+ }
+ }
+ }
+
+ public void OnDropAvailableIO(IOVM ioVM)
+ {
+ Controllers.Add(ioVM);
+ AvailableControllers.Remove(ioVM);
+ }
+ }
+}