RobotManage.cs
6.1 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
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 XRay XRay=new XRay("XRay", XRayType.Spellman_RS232);
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 List<IRobot> robots = new List<IRobot>();
public static bool offlinemode = false;
public static ReelLocation offlinereelLocation = new ReelLocation();
public static int ProductivityCount = 0;
public static int DefectiveCount = 0;
public static void Init() {
try
{
string msgs = "";
xrayMachine = new XRayMachine();
robots.AddRange(new IRobot[] { xrayMachine });
//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();
if (!XRay.Open(Setting_Init.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(Setting_Init.XRay_Voltage.ToString(), Setting_Init.XRay_Current.ToString()))
{
msgs += crc.GetString("device_xray_setvc_failed", "X光电压电流设置失败:{0},{1}\n", Setting_Init.XRay_Voltage.ToString(), Setting_Init.XRay_Current.ToString());
IsLoadOk = false;
}
else
LogUtil.info($"xray V:{Setting_Init.XRay_Voltage} ,C:{Setting_Init.XRay_Current} set ok");
if (!xrayImage.Open()) {
msgs += crc.GetString("device_xrayimage_open_failed", $"图像平板打开失败\n");
IsLoadOk = false;
}
//mainMachine = new MainMachine(RobotManage.Config);
if (!IOManager.ConnectionIO())
{
IsLoadOk = false;
msgs += crc.GetString("device_io_open_failed", "IO板卡初始化失败\n");
}
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();
}
public static void UserPause(bool userpause) {
//xrayMachine.UserPause = userpause;
robots.ForEach((device) => device.UserPause= userpause);
if (userpause)
LogUtil.info("用户暂停");
else
LogUtil.info("用户取消暂停");
}
}
}