Program.cs
5.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
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
using log4net.Config;
using log4net.Util.TypeConverters;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DeviceLibrary;
using Common;
using System.IO;
namespace AGVControl
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
XmlConfigurator.Configure(new FileInfo(AppConfigHelper.GetValue(SettingString.log4net_configname)));
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//程序只能运行一次
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(current.ProcessName);
foreach (Process process in processes)
{
if (process.Id == current.Id) continue; //自己
if (process.MainModule.FileName == current.MainModule.FileName)
{
//显示已打开的程序
Window_API.ShowWindow(process.MainWindowHandle, Window_API.SW_RESTORE);
Window_API.SwitchToThisWindow(process.MainWindowHandle, true);
return;
}
}
Start();
Application.Run(new FrmMain());
Stop();
}
private static void Start()
{
LogUtil.info("=====程序开始=====");
ReadConfig();
DeviceLibrary.Context.Charge = new Charge();
DeviceLibrary.Context.Standby = new Standby();
DeviceLibrary.Context.control = new DeviceLibrary.Control();
DeviceLibrary.Context.server = new Agv.Server();
DeviceLibrary.Context.control.Start();
}
private static void Stop()
{
DeviceLibrary.Context.control.Stop();
DeviceLibrary.Context.server.Stop();
LogUtil.info("=====程序结束=====\r\n");
}
private static void ReadConfig()
{
string path;
string[] line;
string[] temp;
bool isuse;
string rfid = "";
DeviceLibrary.Context.agvInfo = new List<Agv_Info>();
path = DeviceLibrary.Context.CONFIG_PATH + SettingString.FileName_AGV;
line = System.IO.File.ReadAllLines(path, Encoding.UTF8);
for (int i = 1; i < line.Length; i++)
{
temp = line[i].Split(',');
if (temp.Length != 5) continue;
//string val = CommonVar.appConfig.AppSettings.Settings[temp[1]].Value;
bool.TryParse(DeviceLibrary.Context.ReadIni(temp[1], SettingString.IsUse), out isuse); //Convert.ToBoolean(val.Split(',')[0]);
rfid = DeviceLibrary.Context.ReadIni(temp[1], SettingString.RFID); //val.Split(',')[1];
DeviceLibrary.Context.agvInfo.Add(new Agv_Info(temp[0], temp[1], temp[2], temp[3], temp[4], isuse, rfid));
}
DeviceLibrary.Context.agvMission = new Dictionary<string, string>();
DeviceLibrary.Context.showNameMissionName = new Dictionary<string, string>();
path = DeviceLibrary.Context.CONFIG_PATH + SettingString.FileName_AgvMission;
line = System.IO.File.ReadAllLines(path, Encoding.UTF8);
for (int i = 1; i < line.Length; i++)
{
temp = line[i].Split(',');
if (temp.Length != 3) continue;
DeviceLibrary.Context.agvMission.Add(temp[1], temp[2]);
DeviceLibrary.Context.showNameMissionName.Add(temp[1], temp[0]);
}
DeviceLibrary.Context.nodeInfo = new List<Agv.ClientNode>();
path = DeviceLibrary.Context.CONFIG_PATH + SettingString.FileName_AgvProductionLine;
line = System.IO.File.ReadAllLines(path, Encoding.GetEncoding("gb2312"));
for (int i = 1; i < line.Length; i++)
{
temp = line[i].Split(',');
if (temp.Length != 3) continue;
bool.TryParse(DeviceLibrary.Context.ReadIni(temp[0], SettingString.IsUse), out bool isUse);
DeviceLibrary.Context.nodeInfo.Add(new Agv.ClientNode(temp[0], temp[1], temp[2], isUse));
}
//加载任务类型
DeviceLibrary.Context.jobTypeInfo = new List<JobType>();
//CommonVar.jobTypeInfo.Add(new PackingJobType());
DeviceLibrary.Context.jobTypeInfo.Add(new BoxOutJobType());
DeviceLibrary.Context.jobTypeInfo.Add(new BoxInJobType());
DeviceLibrary.Context.jobTypeInfo.Add(new ChargeJobType());
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
LogUtil.error("CurrentDomain_UnhandledException", (Exception)e.ExceptionObject);
}
private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
LogUtil.error("Application_ThreadException", e.Exception);
}
}
}