DBLineControl.cs
9.7 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
using log4net;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary.doubleStore;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary
{
/// <summary>
/// 流水线读写文件操作
/// </summary>
public class DBLineControl
{
protected static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 配置需要运行的流水线,同时只有一个流水线运行
/// </summary>
public static List<int> TheLineIdList = new List<int>();
/// <summary>
/// 0=需要等下位机信号,1=不等下位机信号,板子直接通过
/// </summary>
public static int NoWaitSingle = ConfigAppSettings.GetIntValue(Setting_Init.LineNoWaitSingle);
public static int ChangeNum = 0;
/// <summary>
/// 当前使用的产品ID
/// </summary>
public static int CurrProjectID=0;
/// <summary>
/// 当前使用的产品名称
/// </summary>
public static string CurrProjectName="";
public static string CurrM_Time = "";
public static int File_UpdateTime = 300;
/// <summary>
/// 当前的宽度
/// </summary>
public static int CurrWidth=200;
/// <summary>
/// 与iLIB通信的MachineId
/// </summary>
public static string MachineId = ConfigAppSettings.GetValue(Setting_Init.ManchineID);
/// <summary>
/// 远程共享文件夹地址
/// </summary>
public static string RemoteURL = "";
/// <summary>
/// 共享文件夹用户名
/// </summary>
public static string RemoteUsername= "";
/// <summary>
/// 共享文件夹密码
/// </summary>
public static string RemotePassword = "";
/// <summary>
/// 监控文件的过滤条件
/// </summary>
public static string FileListerFilter = "";
public static string CurrAA = "";
public static string currM_Time = "";
public static int PCB_CHECK = 0;
/// <summary>
/// 开始连接远程共享文件夹
/// </summary>
public static void StartConnect()
{
File_UpdateTime = ConfigAppSettings.GetIntValue(Setting_Init.File_UpdateTime);
string line = ConfigAppSettings.GetValue(Setting_Init.TheLineId);
TheLineIdList = new List<int>();
try
{
string[] objs = line.Split(',');
foreach (string str in objs)
{
TheLineIdList.Add(Int32.Parse(str));
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "解析启动的流水线ID时出错:" + ex.ToString());
}
MachineId = ConfigAppSettings.GetValue(Setting_Init.ManchineID);
RemoteURL = ConfigAppSettings.GetValue(Setting_Init.RemoteURL);
RemoteUsername = ConfigAppSettings.GetValue(Setting_Init.RemoteUsername);
RemotePassword = ConfigAppSettings.GetValue(Setting_Init.RemotePassword);
FileListerFilter = ConfigAppSettings.GetValue(Setting_Init.FileListerFilter);
FileGenerated.StartListerDirectory(RemoteURL, "*.*");
//读取所有产品
string appPath = Application.StartupPath;
string programConfig = ConfigAppSettings.GetValue(Setting_Init.ProgramConfig);
Dictionary<string, DBLineProgram> map = CSVProgramReader<DBLineProgram>.AddCSVFile(appPath + programConfig);
}
/// <summary>
/// 更改产品
/// </summary>
/// <param name="AA">产品ID</param>
/// <param name="projectName">产品名称</param>
public static void UpdateProject(string AA, string programName, string m_Time)
{
CurrAA = AA;
currM_Time = m_Time;
string AANumber = AA.Substring(7);
int pID = Convert.ToInt32(AANumber);
if (MachineId.Equals(""))
{
MachineId = ConfigAppSettings.GetValue(Setting_Init.ManchineID);
}
if (AA.Equals(CurrProjectID))
{
return;
}
//获取宽度
int width = GetWidthById(programName);
CurrWidth = width;
LogUtil.info(LOGGER, DBStoreManager.StoreName + "收到产品更改命令:ID【" + AA + "】Name【" + programName + "】width【" + width + "】time【" + m_Time + "】");
//更改失败
if (width <= 0)
{
DBStoreManager.WarnMsg = DBStoreManager.StoreName + "收到产品AA【" + AA + "】PP【" + programName + "】更改命令:更改失败,未找到产品的宽度";
LogUtil.info(LOGGER, DBStoreManager.WarnMsg);
FileGenerated.writeRequestFile(MachineId, AA, programName, FileGenerated.REQUEST_NG, m_Time);
}
ChangeNum++;
CurrProjectID = pID;
CurrProjectName = programName;
CurrM_Time = m_Time;
//如果所有的宽度和当前一样,直接返回ok
bool isOk = true;
foreach (DB_LA_LineBean line in DBStoreManager.StoreLineMap.Values)
{
if (line.Config.IsInDebug == 0 && line.currWidth != CurrWidth && line.storeRunStatus >= StoreRunStatus.Runing)
{
isOk = false;
break;
}
}
if (isOk)
{
FileGenerated.writeRequestFile(MachineId, AA, programName, FileGenerated.REQUEST_OK, m_Time);
//更新文件
FileGenerated.writeLSTFile(MachineId);
LogUtil.info(LOGGER, "收到的宽度和所有的流水线宽度一致,不需要更改宽度,直接返回ok");
}
else
{
LogUtil.info(LOGGER, "需要等待流水线更改宽度后才能OK");
}
}
private static int GetWidthById(string programName)
{
DBLineProgram program = CSVProgramReader<DBLineProgram>.GetProgram(programName);
if (program != null)
{
return program.ProgramWidth;
}
return -1;
}
public static string[] GetProgramList()
{
List<string> list = new List<string>(CSVProgramReader<DBLineProgram>.allProgramMap.Keys);
return list.ToArray();
}
#region 松下流水线轨道计算备份(康奈德,凌华C154,电钢组合版)
////松下流水线轨道计算备份(康奈德,凌华C154,电钢组合版)
//public static int GetNeedMS(int width)
//{
// double newWidht = width;
// //if (width <= 70)
// //{
// // newWidht = width + 2;
// //}
// //else if (width < 120)
// //{
// // newWidht = width - 1;
// //}
// //else if (width < 300)
// //{
// // newWidht = width - 4;
// //}
// //int ms = (int)((double)((newWidht - 64) * 6000 / 130));
// //ms = ms + 1150;
// //return ms;
// int ms = (int)((double)((newWidht - 45) * 44.5));
// if (width <= 70)
// { //70
// ms = (int)((double)((newWidht - 47.5) * 44.5));
// }
// else if (width <= 80)
// { //75
// ms = (int)((double)((newWidht - 47) * 44.5));
// }
// else if (width <= 120)
// { //100
// ms = 0 + (int)((double)((newWidht - 46) * 44.5));
// }
// else if (width <= 200)
// { //200
// ms = 0 + (int)((double)((newWidht - 45) * 44.5));
// }
// ms = ms + 1243;
// return ms;
//}
#endregion
#region (康泰克,康奈德,电钢组合流水线1的轨道计算)
///// <summary>
///// 流水线轨道调宽,(康泰克,康奈德,电钢组合)
///// </summary>
//public static int GetNeedMS(int width)
//{
// double newWidht = width;
// int ms = (int)((double)((newWidht - 52) * 108));
// if (width <= 70)
// { //70
// ms = (int)((double)((newWidht - 51.2) * 108));
// }
// else if (width <= 80)
// { //75
// ms = (int)((double)((newWidht - 51.2) * 108));
// }
// else if (width <= 120)
// { //100
// ms = 0 + (int)((double)((newWidht - 51.6) * 108));
// }
// else if (width <= 200)
// { //200
// ms = 0 + (int)((double)((newWidht - 52) * 108));
// }
// ms = ms + 1243;
// return ms;
//}
#endregion
/// <summary>
/// 轨道调宽需要的脉冲数(硕科步进控制驱动器)
/// </summary>
public static int GetNeedPosition(int width,int homeWidth)
{
//homeWidth是原点的宽度,1068是1毫米的脉冲数
double newWidht = width * 10 + 10 - homeWidth;
int position = (int)newWidht * 1068 / 10;
return position;
}
}
}