RobotManage.cs
4.3 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
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeviceLibrary
{
public static class RobotManage
{
public static MainMachine mainMachine;
public static Robot_Config Config;
public static bool IsLoadOk = true;
public static bool IsDebug = false;
public delegate void LoadFinish(bool state,string msg);
public static event LoadFinish LoadFinishEvent;
public static bool isRunning = false;
public static Asa.PrintLabel PrintBean;
public static ElectricGripper electricGripper;
static string baseDir = Application.StartupPath;
static Thread mainThread;
public static void Init() {
try
{
mainMachine = null;
string msg = "";
string configFile = Path.Combine(baseDir, "config\\Config.csv");
Config = new Robot_Config(0, "", configFile);
Config = (Robot_Config)CSVConfigReader.LoadConfig(Config);
CodeManager.LoadConfig();
PrintBean = new Asa.PrintLabel(Application.StartupPath + "\\Label");
var ElectricGripperPort = ConfigHelper.Config.Get("ElectricGripperPort");
electricGripper = new ElectricGripper();
if (!electricGripper.OpenPort(ElectricGripperPort)) {
msg += $"电夹爪通讯失败:{ElectricGripperPort}\n";
IsLoadOk = false;
}
mainMachine = new MainMachine(RobotManage.Config);
if (!IOManager.ConnectionIOList(new List<string>()))
{
IsLoadOk = false;
msg += "IO板卡初始化失败\n";
}
LoadFinishEvent?.Invoke(IsDebug?IsDebug:IsLoadOk, msg);
}
catch (Exception ex) {
LoadFinishEvent?.Invoke(false, ex.Message);
}
}
public static void LoadDebug() {
LoadFinishEvent?.Invoke(true, "打开调试模式");
}
public static void Start() {
//Init();
if (!IsLoadOk)
{
LogUtil.info("系统还未加载完毕,无法启动");
if (!IsDebug)
return;
}
mainThread = new Thread(new ThreadStart(mainMachine.Run));
mainThread.Start();
isRunning = true;
GC.KeepAlive(mainThread);
Task.Run(()=> {
Task.Delay(1000).Wait();
if (mainMachine.DeviceCheck())
mainMachine.BeginHomeReset(true);
});
}
public static void Stop()
{
LogUtil.info("开始停止系统.");
mainMachine.Stop();
IOManager.CloseAllConnection();
electricGripper.ClosePort();
isRunning = false;
}
public static void UserPause(bool userpause) {
mainMachine.UserPause = userpause;
if (userpause)
LogUtil.info("用户暂停");
else
LogUtil.info("用户取消暂停");
}
public static void IgnoreSafecheck(bool s)
{
mainMachine.IgnoreSafecheck = s;
if (s)
LogUtil.info("用户设置忽略安全检查");
else
LogUtil.info("用户取消忽略安全检查");
}
public static void IgnoreGratingSignal(bool s)
{
mainMachine.IgnoreGratingSignal = s;
if (s)
LogUtil.info("用户设置忽略安全光栅");
else
LogUtil.info("用户取消忽略安全光栅");
}
public static void LoadPrintSetting()
{
string PrintName = ConfigHelper.Config.Get(Setting_Init.PrinterName);
string labelName = ConfigHelper.Config.Get(Setting_Init.LabelName);
RobotManage.PrintBean.LoadLabel(labelName);
RobotManage.PrintBean.Printer(PrintName, false);
LogUtil.info("PrintLabel 打印机初始化完成【" + labelName + "】【" + PrintName + "】");
}
}
}