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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
using FLY.FeedbackRenZiJia.Common;
using FLY.FeedbackRenZiJia.IService;
using FLY.FeedbackRenZiJia.OBJ_INTERFACE;
using FObjBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace FLY.FeedbackRenZiJia.Client
{
public class HeatBufServiceClient : FObj, IHeatBuf
{
IFConn mConn;
UInt32 mServerID;
#region 属性,对外接口
#region 参数
/// <summary>
/// 加热生效曲线,允许为空,则不生效
/// </summary>
[PropertyChanged.DoNotCheckEquality]
public List<int> HeatEffectCurve { get; set; } = new List<int>();
/// <summary>
/// 厚度稳定范围 %, 偏差在范围内,都是稳定的
/// </summary>
public int StableRange { get; set; } = 2;
/// <summary>
/// 厚度稳定范围 %, 加热量变化为0时,偏差在范围内,都是稳定的
/// </summary>
public int StableRange0 { get; set; } = 2;
/// <summary>
/// 对位模式, 加热与厚度相关性阀值, 相关性 >=0.7
/// </summary>
public double ThresholdR { get; set; } = 0.7;
/// <summary>
/// 对位模式 厚度%差 的极差 >= +4%-4%=8%, 单位%
/// </summary>
public int ThresholdMaxMin { get; set; } = 8;
/// <summary>
/// %
/// 最大sigma, 只有当前的sigma 在 最大sigma 与 最小 sigma 内,才能控制
/// </summary>
public int ThresholdSigmaMax { get; set; } = 20;
/// <summary>
/// %
/// 最小sigma, 只有当前的sigma 在 最大sigma 与 最小 sigma 内,才能控制
/// </summary>
public double ThresholdSigmaMin { get; set; } = 2;
/// <summary>
/// 使用这里独立的Kp, 与 HeatCell 不一样
/// </summary>
public bool IsUsedLocalKp { get; set; }
/// <summary>
/// 本地Kp, 用于判断稳定性
/// </summary>
public double LocalKp { get; set; } = 3;
#endregion
#region 状态
/// <summary>
/// 总延时 =Delay+mRenZiJiaService.FilmLength/mRenZiJiaService.Velocity
/// </summary>
public TimeSpan Delay { get; set; } = TimeSpan.FromSeconds(100);
#region 对位
/// <summary>
/// 进入了对位模式
/// </summary>
public bool IsIntoAutoONo { get; set; }
/// <summary>
/// 对位模式结果
/// </summary>
public EAutoONoResult AutoONoResult { get; set; } = EAutoONoResult.Idle;
/// <summary>
/// 计算的最佳复位区号
/// </summary>
public int BestOrgBoltNo { get; set; } = -1;
/// <summary>
/// 计算的最佳复位区号 对应的 加热/厚度
/// </summary>
public double BestKp { get; set; } = -1;
/// <summary>
/// 计算的最佳复位区号 对应的 加热与厚度相关性
/// </summary>
public double MaxR { get; set; } = -1;
/// <summary>
/// 计算的最佳复位区号 对应的 厚度%变化极差 单位%
/// </summary>
public double MaxMin { get; set; } = -1;
#endregion
#region 稳定性
/// <summary>
/// 当前检测出来的厚度数据 稳定状态
/// </summary>
public STABILITY Stability { get; protected set; } = STABILITY.IDLE;
/// <summary>
/// 当前检测出来的厚度数据 的稳定性
/// </summary>
public double CurrR { get; protected set; } = -1;
/// <summary>
/// 当前检测出来的厚度数据 2Sigma
/// </summary>
public double Curr2Sigma { get; protected set; } = -1;
/// <summary>
/// 当前打散程度。
/// 连续N点都在平均值同一侧为一个块;
/// 这些块的长度平均值/总长度, 为打散度;
/// 打散度越小越好, 最小为 1/NBolts
/// </summary>
public double CurrBreakUp { get; protected set; } = 50;
/// <summary>
/// 当前检测出来的厚度数据,时间
/// </summary>
public DateTime CurrTime { get; protected set; } = DateTime.MinValue;
/// <summary>
/// 当前检测出来的厚度数据,方向
/// </summary>
public Misc.DIRECTION CurrDirection { get; protected set; } = Misc.DIRECTION.FORWARD;
#endregion
#region 列表
/// <summary>
/// 列表最后1个BM
/// </summary>
public int LastBM { get; protected set; }
/// <summary>
/// 列表第1个BM
/// </summary>
public int FirstBM { get; protected set; }
#endregion
#region 每个分区状态
[PropertyChanged.DoNotCheckEquality]
public bool[] BoltIsStable { get; protected set; }
#endregion
#endregion
#endregion
public HeatBufServiceClient(UInt32 serverid)
{
mServerID = serverid;
}
#region IFObj
public override void ConnectNotify(IFConn from)
{
mConn = from;
if (from.IsConnected)
{
FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.GET_PARAMS);
FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.GET_STATE);
FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.GET_BM);
FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATBUF_OBJ_INTERFACE.GET_ISSTABLES);
FObjSys.Current.SenseConfigEx(mConn, mServerID, ID, 0xffffffff, SENSE_CONFIG.ADD);
}
}
public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
{
switch (memid)
{
case HEATBUF_OBJ_INTERFACE.GET_PARAMS:
{
string json = Misc.Converter.BytesToString(infodata);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATBUF_OBJ_INTERFACE.Pack_Params>(json);
HeatEffectCurve = p.HeatEffectCurve;
StableRange = p.StableRange;
StableRange0 = p.StableRange0;
ThresholdR = p.ThresholdR;
ThresholdMaxMin = p.ThresholdMaxMin;
ThresholdSigmaMax = p.ThresholdSigmaMax;
IsUsedLocalKp = p.IsUsedLocalKp;
LocalKp = p.LocalKp;
}
break;
case HEATBUF_OBJ_INTERFACE.GET_STATE:
{
string json = Misc.Converter.BytesToString(infodata);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATBUF_OBJ_INTERFACE.Pack_Status>(json);
Delay = p.Delay;
IsIntoAutoONo = p.IsIntoAutoONo;
AutoONoResult = p.AutoONoResult;
BestOrgBoltNo = p.BestOrgBoltNo;
BestKp = p.BestKp;
MaxR = p.MaxR;
MaxMin = p.MaxMin;
Stability = p.Stability;
CurrR = p.CurrR;
Curr2Sigma = p.Curr2Sigma;
CurrBreakUp = p.CurrBreakUp;
CurrTime = p.CurrTime;
CurrDirection = p.CurrDirection;
}
break;
case HEATBUF_OBJ_INTERFACE.GET_BM:
{
string json = Misc.Converter.BytesToString(infodata);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATBUF_OBJ_INTERFACE.Pack_BM>(json);
FirstBM = p.firstbm;
LastBM = p.lastbm;
}
break;
case HEATBUF_OBJ_INTERFACE.GET_ISSTABLES:
{
string json = Misc.Converter.BytesToString(infodata);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATBUF_OBJ_INTERFACE.Pack_IsStables>(json);
BoltIsStable = p.isStables;
}
break;
}
}
public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
{
switch (funcid)
{
case HEATBUF_OBJ_INTERFACE.CALL_GETHEATDATA:
{
string json = Misc.Converter.BytesToString(retdata);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<FlyData_FeedbackHeat>(json);
((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
}
break;
case HEATBUF_OBJ_INTERFACE.CALL_GETBOLTHEATRECORD:
{
string json = Misc.Converter.BytesToString(retdata);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<FlyData_BoltHeatRecord>(json);
((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
}
break;
}
}
public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
{
PushGetValue(from, srcid, infoid, infodata);
}
public override void Dispose()
{
FObjSys.Current.SenseConfigEx(mConn, mServerID, ID, 0xffffffff, SENSE_CONFIG.REMOVE);
base.Dispose();
}
#endregion
public void Apply()
{
var p = new HEATBUF_OBJ_INTERFACE.Pack_Params()
{
HeatEffectCurve = HeatEffectCurve,
StableRange = StableRange,
StableRange0 = StableRange0,
ThresholdR = ThresholdR,
ThresholdMaxMin = ThresholdMaxMin,
ThresholdSigmaMax = ThresholdSigmaMax,
IsUsedLocalKp = IsUsedLocalKp,
LocalKp = LocalKp
};
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
FObjSys.Current.SetValueEx(
mConn, mServerID, ID,
HEATBUF_OBJ_INTERFACE.SET_PARAMS,
Misc.Converter.StringToBytes(json));
}
public void GetHeatsData(int bookmark, AsyncCBHandler AsyncDelegate, object AsyncState)
{
var p = new HEATBUF_OBJ_INTERFACE.Pack_GetHeatsDataRequest() { bookmark = bookmark };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
HEATBUF_OBJ_INTERFACE.CALL_GETHEATDATA,
Misc.Converter.StringToBytes(json),
AsyncDelegate, AsyncState);
}
public void ClearBoltHeat()
{
CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
HEATBUF_OBJ_INTERFACE.CALL_CLEARBOLTHEAT,
null);
}
/// <summary>
/// 获取每个分区的加热历史 返回 FlyData_BoltHeatRecord
/// </summary>
/// <param name="no">分区号</param>
/// <param name="AsyncDelegate"></param>
/// <param name="AsyncState"></param>
public void GetBoltHeatRecord(int no, AsyncCBHandler AsyncDelegate, object AsyncState)
{
var p = new HEATBUF_OBJ_INTERFACE.Pack_GetBoltHeatRecordRequest() { no = no };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
HEATBUF_OBJ_INTERFACE.CALL_GETBOLTHEATRECORD,
Misc.Converter.StringToBytes(json),
AsyncDelegate, AsyncState);
}
#region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
}