RobotManage.cs
2.4 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
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 = false;
public static bool IsDebug = false;
public delegate void LoadFinish(bool state,string msg);
public static event LoadFinish LoadFinishEvent;
public static bool isRunning = false;
static string baseDir = Application.StartupPath;
static Thread mainThread;
public static void Init() {
try
{
CodeManager.LoadConfig();
string msg = "";
string configFile = Path.Combine(baseDir, "config\\Config.csv");
Config = new Robot_Config(0, "", configFile);
Config = (Robot_Config)CSVConfigReader.LoadConfig(Config);
mainMachine = new MainMachine(RobotManage.Config);
if (!IOManager.ConnectionIOList(new List<string>()))
{
IsLoadOk = false;
msg = "IO板卡初始化失败,无法启动.";
}
else
{
IsLoadOk = true;
}
LoadFinishEvent?.Invoke(IsDebug?IsDebug:IsLoadOk, msg);
}
catch (Exception ex) {
LoadFinishEvent?.Invoke(false, ex.Message);
}
}
public static void Start() {
if (!IsLoadOk)
{
LogUtil.info("系统还未加载完毕,无法启动");
}
mainThread = new Thread(new ThreadStart(mainMachine.Run));
mainThread.Start();
isRunning = true;
GC.KeepAlive(mainThread);
Task.Run(()=> {
Task.Delay(1000).Wait();
mainMachine.BeginHomeReset(true);
});
}
public static void Stop()
{
isRunning = false;
mainMachine.Stop();
}
public static void UserPause(bool userpause) {
mainMachine.UserPause = userpause;
}
}
}