blob: be4c0ffe38e92f47b5bd3a1aaa5d71770f961a0f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.FSE.Common.Diagnostics;
using Tango.FSE.Common.Notifications;
using Tango.PMR.Diagnostics;
namespace Tango.FSE.Diagnostics.Project.Widgets.Output
{
[Description("Digital Output Controller")]
public class OutputWidget : DiagnosticsWidget, ISupportsComponentSelection<TechIos>
{
public TechIos IO { get; set; } = TechIos.GPO_LED1;
private TechIo _techIO;
[JsonIgnore]
public TechIo TechIo
{
get { return _techIO; }
set { _techIO = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(DisplayName)); }
}
[JsonIgnore]
public override string DisplayName
{
get
{
return this.TechIo != null ? this.TechIo.InterfaceName : String.Empty;
}
}
private bool _value;
[JsonIgnore]
public bool Value
{
get { return _value; }
set
{
if (_value != value)
{
_value = value;
RaisePropertyChangedAuto();
OnValueChanged();
}
}
}
private bool _effectiveValue;
[JsonIgnore]
public bool EffectiveValue
{
get { return _effectiveValue; }
set
{
if (_effectiveValue != value)
{
_effectiveValue = value;
RaisePropertyChangedAuto();
_value = value;
RaisePropertyChanged(nameof(Value));
}
}
}
public override async Task Init()
{
int io = (int)IO;
TechIo = await Services.TechComponentsService.IOs.FindOne(x => x.Code == io);
}
public override void OnDiagnosticsData(DiagnosticsPackage package)
{
var state = package.GetDigitalInterfaceState(IO);
if (state != null)
{
EffectiveValue = state.Value;
}
}
private async void OnValueChanged()
{
if (MachineProvider.IsConnected)
{
try
{
await MachineProvider.MachineOperator.SetDigitalOut(new SetDigitalOutRequest() { InterfaceIO = (InterfaceIOs)IO, Value = Value });
}
catch (Exception ex)
{
LogManager.Log(ex, "Error setting digital output state.");
NotificationProvider.PushSnackbarItem(MessageType.Error, "Digital Output Controller Error", true, ex.Message, TimeSpan.FromSeconds(5));
}
}
}
public override FrameworkElement GetView()
{
return new OutputWidgetView();
}
#region Component Selection
public List<DiagnosticsWidgetComponent<TechIos>> Components
{
get
{
return Services.TechComponentsService.IOs.FindAll().Result.Where(x => x.Type == (int)IOType.DigitalOutput).Select(x => new DiagnosticsWidgetComponent<TechIos>()
{
DisplayName = x.InterfaceName,
Object = (TechIos)x.Code,
}).OrderByAlphaNumeric(x => x.DisplayName).ToList();
}
}
public TechIos SelectedComponent
{
get
{
return IO;
}
set
{
if (IO != value)
{
IO = value;
InitAsync();
}
}
}
public bool EnableComponentSelection { get; set; }
#endregion
}
}
|