RobotManage.cs
8.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
using Asa;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using X_Ray;
namespace DeviceLibrary
{
using crc = OnlineStore.CodeResourceControl;
public static class RobotManage
{
public static XRayMachine xrayMachine;
public static LabelMachine labelMachine;
public static FilterMachine filterMachine;
public static T1Machine t1Machine;
public static XRay XRay=new XRay("XRay");
public static XrayImage xrayImage = new Asa.XrayImage("XrayImage", XrayImage.DeviceType.HAOBO_V2);
public static Config_XRay Config;
public static bool IsLoadOk = true;
public static bool IsDebug = false;
/// <summary>
///
/// </summary>
/// <param name="state">加载成功状态</param>
/// <param name="msg">加载消息</param>
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;
public static List<IRobot> robots = new List<IRobot>();
public static WistonAgvClient wistonAgvClient;
public static bool offlinemode = false;
public static ReelLocation offlinereelLocation = new ReelLocation();
public static LineRunMonitor Line1;
public static LineRunMonitor Line2;
public static int ProductivityCount = 0;
public static int DefectiveCount = 0;
//static string baseDir = Application.StartupPath;
public static void Init() {
try
{
string msgs = "";
xrayMachine = new XRayMachine();
labelMachine = new LabelMachine();
filterMachine = new FilterMachine();
t1Machine = new T1Machine();
wistonAgvClient = new WistonAgvClient();
RemoteService.Init();
robots.AddRange(new IRobot[] { xrayMachine, labelMachine, filterMachine, t1Machine });
//robots.AddRange(new IRobot[] { xrayMachine });
robots.ForEach((device)=> {
LogUtil.info(device.DeviceName + " init");
if (!device.Init(out string msg))
{
IsLoadOk = false;
msgs += $"{device.DeviceNameShow} Init Failed\n";
}
LogUtil.info(device.DeviceName + " init end");
});
CodeManager.LoadConfig();
PrintBean = new Asa.PrintLabel(Application.StartupPath + "\\Label",100);
labelMachine.InitPrint();
if (!XRay.Open(ConfigHelper.Config.Get("XRay_Port"), string.Format("{0:yyyy-MM-dd}", DateTime.Now)))
{
msgs += crc.GetString("device_xray_open_failed","X光管通讯失败:{0}\n", ConfigHelper.Config.Get("XRay_Port"));
IsLoadOk = false;
}
else
LogUtil.info("xray init ok");
Thread.Sleep(500);
if (!XRay.SetVC(ConfigHelper.Config.Get("XRay_Voltage"), ConfigHelper.Config.Get("XRay_Current")))
{
msgs += crc.GetString("device_xray_setvc_failed", "X光电压电流设置失败:{0},{1}\n", ConfigHelper.Config.Get("XRay_Voltage"), ConfigHelper.Config.Get("XRay_Current"));
IsLoadOk = false;
}
else
LogUtil.info($"xray V:{ConfigHelper.Config.Get("XRay_Voltage")} ,C:{ConfigHelper.Config.Get("XRay_Current")} set ok");
if (!xrayImage.Open()) {
msgs += crc.GetString("device_xrayimage_open_failed", $"图像平板打开失败\n");
IsLoadOk = false;
}
//xrayImage.Close();
var ElectricGripperPort = ConfigHelper.Config.Get("ElectricGripperPort");
electricGripper = new ElectricGripper(ElectricGripperPort);
if (!electricGripper.OpenPort()) {
msgs += crc.GetString("device_electricGripper_open_failed", "电夹爪通讯失败:{0}\n", ElectricGripperPort);
IsLoadOk = false;
}
electricGripper.HomeReset();
//mainMachine = new MainMachine(RobotManage.Config);
if (!IOManager.ConnectionIO())
{
IsLoadOk = false;
msgs += crc.GetString("device_io_open_failed", "IO板卡初始化失败\n");
}
Line1 = new LineRunMonitor("line1", labelMachine.Config.DOList[IO_Label_Type.Line1_Run].GetIOAddr());
Line2 = new LineRunMonitor("line2", labelMachine.Config.DOList[IO_Label_Type.Line2_Run].GetIOAddr());
LogUtil.info($"XRay StartDate:{UseData.GetStartDateTime},TotalSecond:{UseData.GetTotalUseSeconds},TotalTimes:{UseData.GetTimes}");
var wiston_spnlist = ConfigHelper.Config.Get<string[]>("wiston_spnlist");
if (wiston_spnlist == null)
wiston_spnlist = new string[] { "" };
xrayMachine.pnlst = new HashSet<string>(wiston_spnlist);
xrayMachine.relmove = ConfigHelper.Config.Get<int>("wiston_relmove", 50);
xrayMachine.ptrycount = ConfigHelper.Config.Get<int>("wiston_strycount", 3);
var a= ConfigHelper.Config.Get<int>("wiston_smaxcount", 10500);
LogUtil.info("加载到特殊pn序列" + string.Join(",", ConfigHelper.Config.Get<string[]>("wiston_spnlist")));
LogUtil.info("加载到相对移动偏移" + xrayMachine.relmove+",重试次数"+ xrayMachine.ptrycount);
LoadFinishEvent?.Invoke(IsDebug?IsDebug:IsLoadOk, msgs);
}
catch (Exception ex) {
LoadFinishEvent?.Invoke(false, ex.ToString());
LogUtil.error(ex.ToString());
}
}
public static void LoadDebug() {
LoadFinishEvent?.Invoke(true, crc.GetString("open_debugmode","打开调试模式"));
}
public static void Start()
{
if (!IsLoadOk)
{
LogUtil.info("系统还未加载完毕,无法启动");
if (!IsDebug)
return;
}
robots.ForEach((device) => device.Run());
isRunning = true;
Task.Run(() =>
{
Task.Delay(1000).Wait();
//开始初始化回原
robots.ForEach((device) =>
{
if (device.DeviceCheck())
device.BeginHomeReset(true);
});
});
}
public static void Stop()
{
LogUtil.info("开始停止系统.");
robots.ForEach((device) => device.Stop());
isRunning = false;
robots.ForEach((device) => device.UserPause = false);
}
public static void ShutDown() {
LogUtil.info("开始关闭系统.");
IOManager.CloseAllConnection();
electricGripper.ClosePort();
}
public static void UserPause(bool userpause) {
//xrayMachine.UserPause = userpause;
robots.ForEach((device) => device.UserPause= userpause);
if (userpause)
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);
PrintBean.LoadLabel(labelName);
PrintBean.Printer(PrintName, false);
LogUtil.info("PrintLabel 打印机初始化完成【" + labelName + "】【" + PrintName + "】");
}
}
}