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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
using GalaSoft.MvvmLight.Command;
using System;
using System.ComponentModel;
using System.Net;
using System.Windows.Controls;
using Unity;
namespace FLY.Thick.Base.UI
{
/// <summary>
/// Page_FlyAD.xaml 的交互逻辑
/// </summary>
public partial class PgFlyAd : Page
{
PgFlyAdVm viewModel;
public PgFlyAd()
{
InitializeComponent();
}
[InjectionMethod]
public void Init(
IUnityContainer container,
IFlyADService flyAdService,
ITDGageService gageService,
IInitParamService initParamService)
{
viewModel = new PgFlyAdVm();
viewModel.Init(flyAdService, gageService, initParamService);
this.DataContext = viewModel;
container.BuildUp(mircoGage);
}
}
public class PgFlyAdVm : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
#region 参数
public bool HasCRC { get; set; }
public IPEndPoint EP { get; set; }
public UInt16 PosOfGrid { get; set; }
public MOTORTYPE MotorType { set; get; }
public UInt16 Ratio01 { get; set; }
public UInt16 Ratio02 { get; set; }
public Int16 PosOffset { set; get; }//脉冲平移
public UInt32 JogVelocity { set; get; }
public int GridSmooth { get; set; }
public bool IsCalSpeed { get; set; }
public int ADLag { get; set; }
public bool HasPosMaxMin { get; set; }
public int PosMin { get; set; }
public int PosMax { get; set; }
#endregion
public int Version { get; set; }
public int HardwareVersion { get; set; }
#region initparam
public double Encoder1_mmpp { get; set; }
public int PosLength { get; set; }
/// <summary>
/// 设置的速度,与 实际速度比例 Speed1 = VScan*Speed1Scale
/// </summary>
public double Speed1Scale { get; set; }
#region 速度
/// <summary>
/// 调试时速度,向前走,向后走 Velocity Of JOG
/// </summary>
public UInt32 VJOG { get; set; }
/// <summary>
/// 开始速度 Start Velocity
/// </summary>
public UInt32 SVelocity { set; get; }
/// <summary>
/// 加速时间
/// </summary>
public UInt32 ATime { set; get; }
/// <summary>
/// 减速时间
/// </summary>
public UInt32 DTime { set; get; }
/// <summary>
/// 归0速度1
/// </summary>
public UInt32 HVelocity1 { set; get; }
/// <summary>
/// 归0速度2
/// </summary>
public UInt32 HVelocity2 { set; get; }
#endregion
#endregion
public int TargetPos { get; set; }
#region Command
public RelayCommand ApplyCmd { get; }
public RelayCommand Apply2Cmd { get; }
public RelayCommand RunToCmd { get; }
public RelayCommand BackwCmd { get; }
public RelayCommand ForwCmd { get; }
public RelayCommand OrgCmd { get; }
public RelayCommand StopCmd { get; }
#endregion
IFlyADService flyAdService;
ITDGageService gageService;
IInitParamService initParamService;
public PgFlyAdVm()
{
ApplyCmd = new RelayCommand(Apply);
Apply2Cmd = new RelayCommand(Apply2);
RunToCmd = new RelayCommand(RunTo);
BackwCmd = new RelayCommand(Backw);
ForwCmd = new RelayCommand(Forw);
OrgCmd = new RelayCommand(Org);
StopCmd = new RelayCommand(Stop);
}
public void Init(
IFlyADService flyAdService,
ITDGageService gageService,
IInitParamService initParamService)
{
this.flyAdService = flyAdService;
this.gageService = gageService;
this.initParamService = initParamService;
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.HasCRC), this, nameof(HasCRC));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.Addr), () =>
{
EP = Misc.StringConverter.ToIPEndPoint(this.flyAdService.Addr);
});
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.PosOfGrid), this, nameof(PosOfGrid));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.MotorType), this, nameof(MotorType));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.Ratio01), this, nameof(Ratio01));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.Ratio02), this, nameof(Ratio02));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.PosOffset), this, nameof(PosOffset));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.JogVelocity), this, nameof(JogVelocity));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.GridSmooth), this, nameof(GridSmooth));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.ADLag), this, nameof(ADLag));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.HasPosMaxMin), this, nameof(HasPosMaxMin));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.PosMin), this, nameof(PosMin));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.PosMax), this, nameof(PosMax));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.Verson), this, nameof(Version));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.HardwareVersion), this, nameof(HardwareVersion));
Misc.BindingOperations.SetBinding(this.initParamService, nameof(this.initParamService.Encoder1_mmpp), this, nameof(Encoder1_mmpp));
Misc.BindingOperations.SetBinding(this.initParamService, nameof(this.initParamService.Speed1Scale), this, nameof(Speed1Scale));
Misc.BindingOperations.SetBinding(this.initParamService, nameof(this.initParamService.PosLength), this, nameof(PosLength));
Misc.BindingOperations.SetBinding(this.initParamService, nameof(this.initParamService.VJOG), this, nameof(VJOG));
Misc.BindingOperations.SetBinding(this.initParamService, nameof(this.initParamService.SVelocity), this, nameof(SVelocity));
Misc.BindingOperations.SetBinding(this.initParamService, nameof(this.initParamService.ATime), this, nameof(ATime));
Misc.BindingOperations.SetBinding(this.initParamService, nameof(this.initParamService.DTime), this, nameof(DTime));
Misc.BindingOperations.SetBinding(this.initParamService, nameof(this.initParamService.HVelocity1), this, nameof(HVelocity1));
Misc.BindingOperations.SetBinding(this.initParamService, nameof(this.initParamService.HVelocity2), this, nameof(HVelocity2));
}
private void Apply()
{
if (this.EP == null)
{
FLY.ControlLibrary.Window_WarningTip.Show("警告",
"地址不能为空",
TimeSpan.FromSeconds(2));
}
if (!WdPassword.Authorize("FlyAd"))
return;
flyAdService.HasCRC = this.HasCRC;
flyAdService.Addr = this.EP.ToString();
flyAdService.PosOfGrid = this.PosOfGrid;
flyAdService.MotorType = this.MotorType;
flyAdService.Ratio01 = this.Ratio01;
flyAdService.Ratio02 = this.Ratio02;
flyAdService.PosOffset = this.PosOffset;
flyAdService.JogVelocity = this.JogVelocity;
flyAdService.GridSmooth = this.GridSmooth;
flyAdService.ADLag = this.ADLag;
flyAdService.HasPosMaxMin = this.HasPosMaxMin;
flyAdService.PosMin = this.PosMin;
flyAdService.PosMax = this.PosMax;
flyAdService.HardwareVersion = HardwareVersion;
FLY.ControlLibrary.Window_Tip.Show("应用成功",
null,
TimeSpan.FromSeconds(2));
}
private void Apply2()
{
if (!WdPassword.Authorize("InitParam"))
return;
initParamService.Encoder1_mmpp = Encoder1_mmpp;
initParamService.PosLength = PosLength;
initParamService.VJOG = this.VJOG;
initParamService.SVelocity = this.SVelocity;
initParamService.ATime = this.ATime;
initParamService.DTime = this.DTime;
initParamService.HVelocity1 = this.HVelocity1;
initParamService.HVelocity2 = this.HVelocity2;
initParamService.Apply();
FLY.ControlLibrary.Window_Tip.Show("应用成功",
null,
TimeSpan.FromSeconds(2));
}
private void RunTo()
{
gageService.StartP2(STARTP2_MODE.RUNTO, TargetPos);
}
private void Stop()
{
gageService.StartP2(STARTP2_MODE.STOP);
}
private void Org()
{
gageService.StartP2(STARTP2_MODE.ORG);
}
private void Forw()
{
gageService.StartP2(STARTP2_MODE.FORW_UNTIL_STOP);
}
private void Backw()
{
gageService.StartP2(STARTP2_MODE.BACKW_UNTIL_STOP);
}
}
}