RobotManager.cs
3.9 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
using log4net;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary
{
public class LineManager
{
public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static VMILineBean VMILine = null;
public static VMLLineConfig Config = null;
private static bool isInit = false;
public static bool IsConnectServer = !ConfigAppSettings.GetValue(Setting_Init.http_server).Equals("");
public LineManager()
{
}
public static void CheckEnum(Type type)
{
if (type.IsEnum)
{
List<int> valueList = new List<int>();
foreach (int item in Enum.GetValues(type))
{
if (valueList.Contains(item))
{
LogUtil.error(LOGGER, type.Name + "枚举值:" + item + "重复存在,请检查代码!");
Application.Exit();
break;
}
valueList.Add(item);
}
}
}
public static VMILineBean InitStore()
{
try
{
RobotConfig.ProIOIpMap = new Dictionary<string, string>();
if (!isInit)
{
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
if (server.Equals(""))
{
IsConnectServer = false;
}
CheckEnum(typeof(MoveStep));
CheckEnum(typeof(RunStatus));
isInit = true;
string appPath = Application.StartupPath;
string linefilePath = appPath + ConfigAppSettings.GetValue(Setting_Init.Line_Config);
LogUtil.info(LOGGER, " 开始加载VMI流水线配置:" + linefilePath);
RobotConfig storeConfig = CSVConfigReader.LoadConfig(linefilePath);
Config = (VMLLineConfig)storeConfig;
VMILine = new VMILineBean(Config);
LogUtil.info(LOGGER, "加载VMI流水线完成!");
return VMILine;
}
}
catch (Exception ex)
{
LOGGER.Error("出错:", ex);
MessageBox.Show(ex.ToString(), "加载配置错误(请检查配置)");
Application.Exit();
}
return VMILine;
}
public static bool checkWatch(Stopwatch watch, int targetMs, bool isStop = true)
{
if (!watch.IsRunning)
{
watch.Restart();
return false;
}
else if (watch.ElapsedMilliseconds >= targetMs)
{
watch.Stop();
return true;
}
return false;
}
public static string GetRunStr(RunStatus runs)
{
string sta = "运行中";
switch (runs)
{
case RunStatus.Busy:
sta = "忙碌";
break;
case RunStatus.HomeMoving:
sta = "原点返回";
break;
case RunStatus.Reset:
sta = "重置";
break;
case RunStatus.Runing:
sta = "运行中";
break;
case RunStatus.Wait:
sta = "等待启动";
break;
}
return sta;
}
}
}