Program.cs
9.2 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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DoubleLine
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
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)
{
//显示已打开的程序
API.ShowWindow(process.MainWindowHandle, API.SW_RESTORE);
API.SwitchToThisWindow(process.MainWindowHandle, true);
return;
}
}
string path = System.Configuration.ConfigurationManager.AppSettings["LogPath"];
Common.log = new Asa.File.Log(path, "DoubleLine");
Common.log.OutString("=====程序开始=====");
Common.BenqAGV = new BLL.BenQ_AGV();
Common.Web = new BLL.WebService();
Common.ControlCenter = new BLL.ControlCenter();
ReadConfig();
Application.Run(new FrmMain());
Common.ABB.Exit();
Common.RFID.Close();
Common.log.OutInfo("关闭RFID");
Common.LineDouble.Exit();
Common.LinePack.Exit();
Common.LineDischarge.Exit();
Common.ControlCenter.Exit();
Common.BenqAGV.Close();
if (Common.RFID != null) Common.RFID.Close();
Common.log.OutString("=====程序结束=====\r\n");
Common.log.Dispose();
//System.Threading.Thread.Sleep(100);
//Environment.Exit(0);
}
private static void ReadConfig()
{
Common.ABB = new BLL.ABB();
Common.ABB_Info = new ABBInfo[3];
for (int i = 0; i < Common.ABB_Info.Length; i++)
{
string dev = "ABB" + (i + 1);
string ip = System.Configuration.ConfigurationManager.AppSettings[dev + "_IP"];
string ss = System.Configuration.ConfigurationManager.AppSettings[dev + "_Speed"];
int.TryParse(ss, out int speed);
Common.ABB_Info[i] = new ABBInfo(dev, ip, speed);
}
Common.RFID = new Asa.RFID.ReaderAll();
Common.RFID_Info = new RFIDInfo[7];
for (int i = 0; i < Common.RFID_Info.Length; i++)
{
string dev = "RFID" + (i + 1);
string name = System.Configuration.ConfigurationManager.AppSettings[dev + "_Name"];
string ip = System.Configuration.ConfigurationManager.AppSettings[dev + "_IP"];
Common.RFID_Info[i] = new RFIDInfo(name, ip);
}
Common.LineDouble = new BLL.LineDouble();
Common.LinePack = new BLL.LinePack();
Common.LineDischarge = new BLL.LineDischarge();
Common.IO_Info = new IOInfo[6];
for (int i = 0; i < Common.IO_Info.Length; i++)
{
string dev = "IO" + (i + 1);
string name = System.Configuration.ConfigurationManager.AppSettings[dev + "_Name"];
string ip = System.Configuration.ConfigurationManager.AppSettings[dev + "_IP"];
Common.IO_Info[i] = new IOInfo(name, ip);
}
DoubleLineIO_ReadConfig();
PackLineIO_ReadConfig();
DischargeLineIO_ReadConfig();
}
private static void DoubleLineIO_ReadConfig()
{
string path = AppDomain.CurrentDomain.BaseDirectory + "Explain\\DoubleIO.csv";
try
{
Common.IO_Info[0].DI = new Register[16];
Common.IO_Info[0].DO = new Register[16];
Common.IO_Info[0].Box.SetInput(Asa.IOModule.Box_Type.DI, 16);
Common.IO_Info[0].Box.SetOutput(Asa.IOModule.Box_Type.DO, 16);
Common.IO_Info[0].Box.AutoReadInput(true, 100);
Common.IO_Info[1].DI = new Register[16];
Common.IO_Info[1].DO = new Register[16];
Common.IO_Info[1].Box.SetInput(Asa.IOModule.Box_Type.DI, 16);
Common.IO_Info[1].Box.SetOutput(Asa.IOModule.Box_Type.DO, 16);
Common.IO_Info[1].Box.AutoReadInput(true, 100);
Common.IO_Info[2].DI = new Register[8];
Common.IO_Info[2].DO = new Register[24];
Common.IO_Info[2].Box.SetInput(Asa.IOModule.Box_Type.DI, 8);
Common.IO_Info[2].Box.SetOutput(Asa.IOModule.Box_Type.DO, 24);
Common.IO_Info[2].Box.AutoReadInput(true, 100);
string[] text = System.IO.File.ReadAllLines(path);
for (int i = 0; i < text.Length; i++)
{
if (i == 96) break;
string[] temp = text[i].Split(',');
if (temp.Length != 2) continue;
if (i < 16)
Common.IO_Info[0].DI[i] = new Register("DI_" + (i + 1), temp[0], temp[1]);
else if (i < 32)
Common.IO_Info[0].DO[i - 16] = new Register("DO_" + (i - 15), temp[0], temp[1]);
else if (i < 48)
Common.IO_Info[1].DI[i - 32] = new Register("DI_" + (i - 31), temp[0], temp[1]);
else if (i < 64)
Common.IO_Info[1].DO[i - 48] = new Register("DO_" + (i - 47), temp[0], temp[1]);
else if (i < 72)
Common.IO_Info[2].DI[i - 64] = new Register("DI_" + (i - 63), temp[0], temp[1]);
else if (i < 96)
Common.IO_Info[2].DO[i - 72] = new Register("DO_" + (i - 71), temp[0], temp[1]);
}
Common.log.OutInfo("读取DoubleLineIO配置文件完成");
}
catch (Exception ex)
{
Common.log.OutError(ex);
}
}
private static void PackLineIO_ReadConfig()
{
string path = AppDomain.CurrentDomain.BaseDirectory + "Explain\\PackingIO.csv";
try
{
Common.IO_Info[3].DI = new Register[16];
Common.IO_Info[3].DO = new Register[16];
Common.IO_Info[3].Box.SetInput(Asa.IOModule.Box_Type.DI, 16);
Common.IO_Info[3].Box.SetOutput(Asa.IOModule.Box_Type.DO, 16);
Common.IO_Info[3].Box.AutoReadInput(true, 100);
string[] text = System.IO.File.ReadAllLines(path);
for (int i = 0; i < text.Length; i++)
{
if (i == 32) break;
string[] temp = text[i].Split(',');
if (temp.Length != 2) continue;
if (i < 16)
Common.IO_Info[3].DI[i] = new Register("DI_" + (i + 1), temp[0], temp[1]);
else if (i < 32)
Common.IO_Info[3].DO[i - 16] = new Register("DO_" + (i - 15), temp[0], temp[1]);
}
Common.log.OutInfo("读取PackingIO配置文件完成");
}
catch (Exception ex)
{
Common.log.OutError(ex);
}
}
private static void DischargeLineIO_ReadConfig()
{
try
{
Common.IO_Info[4].DI = new Register[8];
Common.IO_Info[4].DO = new Register[8];
Common.IO_Info[4].Box.SetInput(Asa.IOModule.Box_Type.DI, 8);
Common.IO_Info[4].Box.SetOutput(Asa.IOModule.Box_Type.DO, 8);
Common.IO_Info[4].Box.AutoReadInput(true, 100);
Common.IO_Info[5].DI = new Register[8];
Common.IO_Info[5].DO = new Register[8];
Common.IO_Info[5].Box.SetInput(Asa.IOModule.Box_Type.DI, 8);
Common.IO_Info[5].Box.SetOutput(Asa.IOModule.Box_Type.DO, 8);
Common.IO_Info[5].Box.AutoReadInput(true, 100);
Common.log.OutInfo("读取DischargeLineIO配置文件完成");
}
catch (Exception ex)
{
Common.log.OutError(ex);
}
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Common.log.OutError((Exception)e.ExceptionObject);
}
private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
Common.log.OutError(e.Exception);
}
}
}