MainMachine.cs
5.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
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeviceLibrary
{
public partial class MainMachine// : IRobot<Robot_Config>
{
public string Name { get; set; } = "DualSISO";
private bool _canRunning = true;
public bool canRunning
{
get { return _canRunning; }
set
{
if (_canRunning != value) {
//Msg.setlogones();
}
_canRunning = value;
}
}
public bool isAlarm { get=>RobotManage.Stores.Sum(s=>s.isAlarm?1:0)>0;}
public RunStatus runStatus { get; set; } = RunStatus.Stop;
public Robot_Config Config { get; set; }
public bool UserPause { get; set; } = false;
/// <summary>
/// 是否在急停中
/// </summary>
public bool isInSuddenDown = false;
public MainMachine(Robot_Config _config) {
Config = _config;
crc.LanguageChangeEvent += Crc_LanguageChangeEvent;
#region 初始化led灯
RunningLed = new Led(Config.DOList[IO_Type.Run_Led].GetIOAddr(),LedColor.green);
StandbyLed = new Led(Config.DOList[IO_Type.Standby_Led].GetIOAddr(), LedColor.yellow);
AlarmLed = new Led(Config.DOList[IO_Type.Alarm_Led].GetIOAddr(), LedColor.red);
#endregion
#region 初始化伺服轴
Crc_LanguageChangeEvent(null, EventArgs.Empty);
#endregion
AlarmBuzzer.SetOnOffAction(() =>{ IOMove(IO_Type.Alarm_Buzzer, IO_VALUE.HIGH,Config); }, () => { IOMove(IO_Type.Alarm_Buzzer, IO_VALUE.LOW, Config); });
IOMonitor.RegisterIO(IO_Type.Reset_BTN, Config, IO_VALUE.HIGH, Reset_BTN, 2500, 100);
LedProcessInit();
}
private void Crc_LanguageChangeEvent(object sender, EventArgs e)
{
}
//public bool hasAlarm = false;
/// <summary>
/// 整机启动变量,设置为false后将退出线程,只在停止时调用
/// </summary>
bool mstart=true;
public void Run() {
mstart = true;
while (mstart) {
try
{
canRunning = DeviceCheck();
if (canRunning)
{
BtnProcess();
canRunning = SafeCheck();
}
Thread.Sleep(200);
if (!canRunning || !mstart)
continue;
if (runStatus == RunStatus.Running)
{
ioMonitor();
}
else if (runStatus == RunStatus.HomeReset)
{
//HomeReset();
}
}
catch (Exception ex)
{
MsgService.Add(ex.ToString(), MsgLevel.warning);
}
finally {
if (isAlarm)
{
AlarmBuzzer.OFF();
}
else {
AlarmBuzzer.ON();
}
}
}
LogUtil.info("主线程已退出.");
}
public void Start() {
Run();
}
public void Stop() {
mstart = false;
UserPause = false;
Thread.Sleep(300);
LedProcess(null);
}
public bool IgnoreGratingSignal = false;
bool lastSafeCheckStatus = true;
bool SafeCheck() {
bool ok = true;
lastSafeCheckStatus = ok;
return ok;
}
void DeviceSuddenStop() {
if (lastSafeCheckStatus)
{
}
}
public bool DeviceCheck() {
bool ok = true;
isInSuddenDown = IOValue(IO_Type.SuddenStop_BTN, Config).Equals(IO_VALUE.LOW);
if (UserPause)
{
MsgService.Add(crc.GetString("Res0133","系统暂停"), MsgLevel.warning);
DeviceSuddenStop();
lastSafeCheckStatus = false;
ok = false;
return ok;
}
else if (isInSuddenDown)
{
MsgService.Add(crc.GetString("Res0134","急停中"), MsgLevel.alarm);
ok = false;
}
return ok;
}
public IO_VALUE IOValue(string ioType, DeviceConfig config) => IOManager.IOValue(ioType, config);
void IOMove(string IoType, IO_VALUE value, DeviceConfig config, bool isCheck = false, int msTime = 0)
{
if (msTime <= 0)
{
if (isCheck && (IOValue(IoType, config).Equals(value)))
{
return;
}
IOManager.IOMove(IoType, value, config);
}
else
{
Task.Run(() =>
{
IOManager.IOMove(IoType, value, config);
Thread.Sleep(msTime);
IO_VALUE tValue = value.Equals(IO_VALUE.HIGH) ? IO_VALUE.LOW : IO_VALUE.HIGH;
LogUtil.info(Name + "定时回写IO: [" + IoType + "]=[" + value + "],msTime=" + msTime);
IOManager.IOMove(IoType, tValue, config);
});
}
}
}
}