App.xaml.cs
13.5 KB
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
using Microsoft.Extensions.Configuration;
using RCS.Communication;
using RCS.Dal;
using RCS.Model.ClientMoel;
using RCS.Model.Entity;
using RCS.Model.ManualModel;
using RCS.Model.PLC;
using RCS.WinClient.Common;
using RCS.WinClient.Views;
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace RCS.WinClient
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
#region 变量属性
/// <summary>
/// 点上下间隔像素
/// </summary>
public static int GsHeight = 36;
/// <summary>
/// 点左右间隔像素
/// </summary>
public static int GsWidth = 36;
/// <summary>
/// 地图最小值Y
/// </summary>
public static int HeightMin = 0;
/// <summary>
/// 地图最大值Y
/// </summary>
public static int HeightMax = 0;
/// <summary>
/// 地图最小值X
/// </summary>
public static int WidthMin = 0;
/// <summary>
/// 地图最大值X
/// </summary>
public static int WidthMax = 0;
/// <summary>
/// 地图显示方向
/// </summary>
public static int Rotote = 2;
/// <summary>
/// 点位的坐标范围(在这个坐标范围内就认为在点位上)
/// </summary>
public static int PointRange = 400;//30;
/// <summary>
/// 地图货架显示集合
/// </summary>
public static List<Rectangle> ShelfSharp = new List<Rectangle>();
/// <summary>
/// 地图小车显示集合
/// </summary>
public static List<Ellipse> AgvSharp = new List<Ellipse>();
/// <summary>
/// 地图点显示集
/// </summary>
public static List<Ellipse> PointSharp = new List<Ellipse>();
/// <summary>
/// 控制界面显示
/// </summary>
public static Canvas Canvas_Monit = null;
/// <summary>
/// 主窗体
/// </summary>
public static MainWindow WinMain = null;
/// <summary>
/// 线程
/// </summary>
public static Dispatcher AppDispatcher;
/// <summary>
/// 监听数量
/// </summary>
public static int ServerConactNum = 50;
/// <summary>
/// 区域个数
/// </summary>
public static int KeyAreaNum = 1;
/// <summary>
/// 满电量
/// </summary>
public static float FullCharge;
/// <summary>
/// 安全电量
/// </summary>
public static float SafeCharge;
/// <summary>
/// 危险电量
/// </summary>
public static float DangerCharge;
/// <summary>
/// 最低充电量
/// </summary>
public static float MinCharges;
/// <summary>
/// AGV车身长度
/// </summary>
public static int AgvLength = 113;
/// <summary>
/// 带货避让的子任务号
/// </summary>
public static uint AvoidSubTaskNo = 9999999;
/// <summary>
/// 连接的AGV客户端
/// </summary>
public static BlockingCollection<ClientControl> ClientWork = new BlockingCollection<ClientControl>();
/// <summary>
/// 存入日志
/// </summary>
public static Log ExFile = new Log();
/// <summary>
/// 界面显示集合
/// </summary>
public static Sharp Sharp = new Sharp();
/// <summary>
/// 参数配置集合
/// </summary>
public static Dictionary<string, Config_KeyValue> Config_KeyValueDic = new Dictionary<string, Config_KeyValue>();
/// <summary>
/// AGV集合
/// </summary>
public static List<Base_Agv> AgvList = new List<Base_Agv>();
/// <summary>
/// 站台集合
/// </summary>
public static List<Base_Station> StationList = new List<Base_Station>();
/// <summary>
/// Point集合
/// </summary>
public static List<Base_Point> PointList = new List<Base_Point>();
/// <summary>
/// 主任务集合
/// </summary>
public static ObservableCollection<Base_Task> TaskList = new ObservableCollection<Base_Task>();
/// <summary>
/// 任务分解设置集合
/// </summary>
public static List<Config_TaskSplit> Config_TaskSplitList = new List<Config_TaskSplit>();
/// <summary>
/// 任务AGV群组匹配关系
/// </summary>
public static List<Config_TaskAgvGroup> TaskAgvGroupList = new List<Config_TaskAgvGroup>();
/// <summary>
/// 单步控制集合
/// </summary>
public static List<SingleControl> SingleControlList = new List<SingleControl>();
/// <summary>
/// 旋转锁定点配置集合
/// </summary>
public static List<Config_Point> Config_PointList = new List<Config_Point>();
/// <summary>
/// 库位地标
/// </summary>
public static List<Base_Loction> LoctionList = new List<Base_Loction>();
/// <summary>
/// 地标集合
/// </summary>
public static List<Base_Point> DemoPointList = new List<Base_Point>();
/// <summary>
/// 所有设备集合
/// </summary>
public static List<Base_Equipment> EquipmentList = new List<Base_Equipment>();
/// <summary>
/// 华恒站台监控
/// </summary>
public static List<HuahengStaion> HuahengStaionList = new List<HuahengStaion>();
/// <summary>
/// 剪床监控
/// </summary>
public static List<Shears> ShearsList = new List<Shears>();
/// <summary>
/// 快卷门监控
/// </summary>
public static List<Door> DoorList = new List<Door>();
public static List<Line> MapLines = [];
/// <summary>
/// AGV信息监控
/// </summary>
public static Dictionary<string, AgvMonitor> AgvMonitorDic = new Dictionary<string, AgvMonitor>();
/// <summary>
/// 错误说明列表
/// </summary>
public static string[] Config_ErrMsgList { set; get; }
/// <summary>
/// agv错误信息
/// </summary>
//public static BlockingCollection<Log_AgvErrMsg> AgvErrMsgs { set; get; } = [];
public static List<Log_AgvErrMsg> AgvErrMsgs { set; get; } = [];
/// <summary>
/// 配置文件
/// </summary>
public static AppConfig AppConfig { get; set; }
public static Dictionary<string, Dictionary<string, (string desc, Func<object, object> func)>?> LogObjectInfoCache { get; set; } = new();
public static Dictionary<string, PropCache> AgvPropCache { get; set; } = [];
public static Dictionary<int, Protocol> Protocols { get; set; } = [];
//是否测试模式
public static bool IsTestMode;
//是否允许站台中旋转
public static bool IsAllowStationRotate;
#endregion
void Application_Startup(object sender, StartupEventArgs e)
{
DispatcherUnhandledException += App_DispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
// 设置文本渲染选项
//RenderOptions.SetTextRenderingMode(Application.Current.MainWindow, TextRenderingMode.ClearType);
//RenderOptions.SetClearTypeHint(Application.Current.MainWindow, ClearTypeHint.Enabled);
Mutex mutex = new Mutex(true, "ElectronicNeedleTherapySystem1", out bool ret);
//if (!ret)
//{
// ComnMethod.Message("已有一个RCS程序实例运行,请勿重新运行!");
// Environment.Exit(0);
// return;
//}
System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("RCS.WinClient");
if (p.Length > 1)
{
ComnMethod.Message("RCS程序已启动,请勿重新运行!");
Environment.Exit(0);
return;
}
//加载配置
var appConfig = new ConfigurationBuilder().AddJsonFile("AppSettings.json").Build().Get<AppConfig>();
if (appConfig == null)
{
ComnMethod.Message("无启动配置文件请检查程序即将推出!");
Environment.Exit(0);
return;
}
AppConfig = appConfig;
DbContext.Log = ExFile.MessageSql;
DbContext.Init(AppConfig.DalOptions);
PLCHelper.PLCHelperLog = ExFile.MessageLog;
//缓存agv属性
AgvPropCache = ComnMethod.GetPropsCacheInfo(typeof(Base_Agv));
WinMain = new MainWindow();
WinMain.Show();
}
/// <summary>
/// 获取参数配置的double值
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static double GetKeyValue(string key)
{
if (!Config_KeyValueDic.TryGetValue(key, out Config_KeyValue? value))
{
throw new Exception($"发生异常:字典中不存在充电需要的参数【{key}】");
}
return value.DoubleValue;
}
#region 异常捕获
/// <summary>
/// Task线程异常
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
{
Exception ex = e.Exception;
string msg = string.Format($"Task线程异常,原因:{ex.Message},\n 堆栈:{ex.StackTrace}");
ExFile.MessageError("App", msg);
}
/// <summary>
/// 非UI线程异常
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject is Exception ex)
{
//异常信息 和 调用堆栈信息
string msg = String.Format($"发生非UI线程异常,程序即将停止,原因:{ex.Message},\n 堆栈:{ex.StackTrace}");
ExFile.MessageError("App_DispatcherUnhandledException", msg);
ComnMethod.Message(msg);
}
}
/// <summary>
/// UI线程异常
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
Exception ex = e.Exception;
//异常信息 和 调用堆栈信息
string msg = string.Format($"UI线程异常,原因:{ex.Message},\n 堆栈:{ex.StackTrace}");
ComnMethod.Message(msg);
ExFile.MessageError("App", msg);
e.Handled = true;
}
#endregion
#region 关机AGV设置
/// <summary>
/// AGV是否要关机,0=不要关机、1=要关机
/// </summary>
public static int offAgv = 0;
/// <summary>
/// 关机时间
/// </summary>
public static DateTime offTime;
/// <summary>
/// 关机AGV编码
/// </summary>
public static List<string> OffAgvNos = new List<string>();
#endregion
#region 测试全局变量
public static int StartCycle = 0;
/// <summary>
/// 测试行走循环任务
/// </summary>
public static List<ManualCycle> ManualCycleList = new List<ManualCycle>();
/// <summary>
/// 循环任务
/// </summary>
public static List<(Base_Agv agv, string taskType)> RecurrentTasks = new();
/// <summary>
/// 随机任务配置
/// </summary>
public static (bool IsStartRadom, int Concurrency, List<string> TaskTypes) RadomTaskConfig;
/// <summary>
/// 测试耦合旋转循环任务变量
/// </summary>
public static int RotateTask = 0;
public static List<string> RotateAgvNo = new List<string>();
public static List<string> RotateStartPoint = new List<string>();
/// <summary>
/// 测试升降循环任务变量
/// </summary>
public static int LiftTask = 0;
public static List<string> LiftAgvNo = new List<string>();
public static List<string> LiftStartPoint = new List<string>();
/// <summary>
/// 测试托盘旋转循环任务变量
/// </summary>
public static int PalletTask = 0;
public static List<string> PalletAgvNo = new List<string>();
public static List<string> PalletStartPoint = new List<string>();
/// <summary>
/// 测试充电电量监测
/// </summary>
public static int ChargeTask = 0;
/// <summary>
/// 异常小车集合
/// </summary>
public static List<string> errAgv = new List<string>();
#endregion
}
}