ElevatorWork.cs
6.8 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
using System;
using System.Collections.Generic;
using System.Text;
using Model;
namespace BLL
{
public class ElevatorWork
{
private Advantech.IO_Module module;
public delegate void IOChanged(bool[] sta);
public event IOChanged DI_Changed;
public event IOChanged DO_Changed;
public delegate void Connected(bool con);
public event Connected Connect_Event;
public ElevatorWork()
{
module = new Advantech.IO_Module(0, 8, 8, 8, "IO_Elevator") { IP = Common.ElevatorIOIP };
module.Connect_Event += Module_Connect_Event;
module.DO_Changed_Event += Module_DO_Changed_Event;
module.DI_Changed_Event += Module_DI_Changed_Event;
}
public void Open()
{
module.Open();
}
public void Close()
{
module.Close();
}
public void WriteDO(int index)
{
int add = Common.elevatorInfos[index].Address;
Advantech.IO_State sta = module.ReadDO(add);
sta = module.ReverseStatus(sta);
module.WriteDO(add, sta);
Common.log.Info(string.Format("手动操作 {0}={1}", Common.elevatorInfos[index].Name, sta.ToString()));
}
public IJob GetJob()
{
bool sta = GetRecycle();
if (sta)
{
Common.log.Info("电梯送空架子呼叫");
return new RecycleJob();
}
else
{
Common.log.Debug("没有找到电梯送空架子呼叫");
return null;
}
}
public bool GetRecycle()
{
int idx1 = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_EMPTY_SHELF);
if (idx1 == -1) return false;
bool sta1 = Common.elevatorInfos[idx1].State;
int idx2 = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_OPEN_DOOR);
if (idx2 == -1) return false;
bool sta2 = Common.elevatorInfos[idx2].State;
return sta1 && sta2;
}
public void UseAsk()
{
int idx = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_USE_ASK);
if (idx == -1) return;
module.WriteDO(Common.elevatorInfos[idx].Address, Advantech.IO_State.On);
}
public bool UseAnswer()
{
int idx = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_USE_ANSWER);
if (idx == -1) return false;
return Common.elevatorInfos[idx].State;
}
public void CallElevator(bool sta)
{
int idx = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_CALL);
if (idx == -1) return;
module.WriteDO(Common.elevatorInfos[idx].Address, sta ? Advantech.IO_State.On : Advantech.IO_State.Off);
}
public bool ArriveFloor()
{
int idx = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_ARRIVE_FLOOR);
if (idx == -1) return false;
return Common.elevatorInfos[idx].State;
}
public bool OpenDoor()
{
int idx = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_OPEN_DOOR);
if (idx == -1) return false;
return Common.elevatorInfos[idx].State;
}
public void FullShelfLeave()
{
//送满料
int idx = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_FULL_SHELF);
if (idx == -1) return;
module.WriteDO(Common.elevatorInfos[idx].Address, Advantech.IO_State.On);
//离开信号
idx = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_LEAVE);
if (idx == -1) return;
module.WriteDO(Common.elevatorInfos[idx].Address, Advantech.IO_State.On);
}
public void EmptyShelfLeave()
{
//离开信号
int idx = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_LEAVE);
if (idx == -1) return;
module.WriteDO(Common.elevatorInfos[idx].Address, Advantech.IO_State.On);
}
public void EndTask()
{
int idx = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_FULL_SHELF);
if (idx == -1) return;
module.WriteDO(Common.elevatorInfos[idx].Address, Advantech.IO_State.Off);
idx = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_LEAVE);
if (idx == -1) return;
module.WriteDO(Common.elevatorInfos[idx].Address, Advantech.IO_State.Off);
idx = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_USE_ASK);
if (idx == -1) return;
module.WriteDO(Common.elevatorInfos[idx].Address, Advantech.IO_State.Off);
idx = Common.elevatorInfos.FindIndex(s => s.Key == Common.ELEVATOR_CALL);
if (idx == -1) return;
module.WriteDO(Common.elevatorInfos[idx].Address, Advantech.IO_State.Off);
}
private void Module_Connect_Event(Advantech.IO_Module box)
{
Connect_Event?.Invoke(box.IsConn);
}
private void Module_DO_Changed_Event(Advantech.IO_Module box, Advantech.IO_State[] sta)
{
List<bool> work = new List<bool>();
for (int i = 0; i < Common.elevatorInfos.Count; i++)
{
if (Common.elevatorInfos[i].Type == "DO")
{
int idx = Common.elevatorInfos[i].Address;
if (idx < sta.Length)
{
Common.elevatorInfos[i].State = sta[idx] == Advantech.IO_State.On;
}
work.Add(Common.elevatorInfos[i].State);
}
}
DO_Changed?.Invoke(work.ToArray());
}
private void Module_DI_Changed_Event(Advantech.IO_Module box, Advantech.IO_State[] sta)
{
List<bool> work = new List<bool>();
List<string> content = new List<string>();
for (int i = 0; i < Common.elevatorInfos.Count; i++)
{
if (Common.elevatorInfos[i].Type == "DI")
{
int idx = Common.elevatorInfos[i].Address;
if (idx < sta.Length)
{
Common.elevatorInfos[i].State = sta[idx] == Advantech.IO_State.On;
}
work.Add(Common.elevatorInfos[i].State);
content.Add(Common.elevatorInfos[i].ToText());
}
}
//System.IO.File.WriteAllLines(Common.PATH_ELEVATOR_WORK, content, Encoding.UTF8);
DI_Changed?.Invoke(work.ToArray());
}
}
}