自动化立体仓库 - WCS系统
Junjie
2023-12-25 2dc3f0507d6e883d16b1c3c095ca06455a6fa1a7
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
package com.zy.asrs.task;
 
import HslCommunication.Core.Types.OperateResult;
import HslCommunication.Core.Types.OperateResultExOne;
import HslCommunication.Profinet.Siemens.SiemensPLCS;
import HslCommunication.Profinet.Siemens.SiemensS7Net;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.SiemensDevpThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.Map;
 
@Component
public class DevpReadScheduler {
 
    @Autowired
    private SlaveProperties slaveProperties;
 
    //出入库站点检测报警信息
    public static final ArrayList<Integer> outInAlarmStaNos = new ArrayList<Integer>(){{
        add(101);add(102);add(104);
        add(201);add(202);add(204);
        add(340);add(345);
    }};
 
    public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{
        add(302);add(304);
        add(305);add(306);
        add(307);add(308);
        add(310);add(311);
        add(312);add(313);
        add(314);add(315);
        add(316);add(318);
        add(319);add(320);
        add(321);add(322);
        add(323);add(324);
        add(326);add(327);
        add(328);add(329);
        add(330);add(332);
        add(334);add(335);
        add(336);add(337);
        add(338);add(342);
        add(343);add(344);
    }};
 
    public static final ArrayList<Integer> staNos3 = new ArrayList<Integer>() {{//218
        add(302);add(304);
        add(315);add(322);
        add(324);add(330);
        add(332);add(337);
    }};
 
    public static final ArrayList<Integer> staNos4 = new ArrayList<Integer>() {{//250
        add(318);add(320);
        add(343);
    }};
 
    @Scheduled(cron = "0/1 * * * * ? ")
    public void read() {
        try {
            for (DevpSlave slave : slaveProperties.getDevp()) {
                SiemensS7Net siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, slave.getIp());
                siemensS7Net.setRack(slave.getRack().byteValue());
                siemensS7Net.setSlot(slave.getSlot().byteValue());
                OperateResult connect = siemensS7Net.ConnectServer();
 
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, slave.getId());
                Map<Integer, StaProtocol> station = devpThread.getStation();
                if (connect.IsSuccess) {
                    //出入库站点检测报警信息
                    Thread.sleep(100);
                    for (Integer staNo : outInAlarmStaNos) {
                        OperateResultExOne<byte[]> result5 = siemensS7Net.Read("DB" + staNo + ".20.0", (short) 2);
                        if (result5.IsSuccess) {
                            if (staNo == 101 || staNo == 201) {
                                staNo--;
                            } else {
                                staNo++;
                            }
                            StaProtocol staProtocol = station.get(staNo);
                            boolean[] status = siemensS7Net.getByteTransform().TransBool(result5.Content, 0, 2);
                            staProtocol.setBarcodeErr(status[4]);//扫码失败
                            staProtocol.setFrontErr(status[8]);//前超限
                            staProtocol.setBackErr(status[9]);//后超限
                            staProtocol.setLeftErr(status[10]);//左超限
                            staProtocol.setRightErr(status[11]);//右超限
                            staProtocol.setHighErr(status[12]);//超高
                            staProtocol.setWeightErr(status[13]);//超重
                        }
                    }
 
                    Thread.sleep(100);
                    for (Integer staNo : staNos2) {
                        OperateResultExOne<byte[]> result5 = siemensS7Net.Read("DB" + staNo + ".0", (short) 48);
                        if (result5.IsSuccess) {
                            StaProtocol staProtocol = station.get(staNo);
                            StaProtocol staProtocol300 = station.get(300);
                            if (null == staProtocol) {
                                staProtocol = new StaProtocol();
                                staProtocol.setSiteId(staNo);
                                station.put(staNo, staProtocol);
                            }
 
                            boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result5.Content, 1, 1);
                            staProtocol.setAutoing(staProtocol300.isAutoing());  // 自动
                            staProtocol.setLoading(!status1[2]);  // 有物
 
                            if (staNos3.contains(staNo) || staNos4.contains(staNo)) {
                                continue;
                            }
                            if (staNo == 344) {
                                staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt16(result5.Content, 34));     // 工作号
                            } else {
                                staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt16(result5.Content, 22));     // 工作号
                            }
                        }
                    }
 
                    Thread.sleep(100);
                    for (Integer staNo : staNos3) {
                        OperateResultExOne<byte[]> result5 = siemensS7Net.Read("DB" + staNo + ".22.0", (short) 2);
                        OperateResultExOne<byte[]> result6 = siemensS7Net.Read("DB" + staNo + ".218.0", (short) 2);
                        if (result5.IsSuccess && result6.IsSuccess) {
                            StaProtocol staProtocol = station.get(staNo);
                            short wrkNo1 = siemensS7Net.getByteTransform().TransInt16(result5.Content, 0);
                            short wrkNo2 = siemensS7Net.getByteTransform().TransInt16(result6.Content, 0);
                            short wrkNo = 0;
                            if (wrkNo1 != 0) {
                                wrkNo = wrkNo1;
                            }
                            if (wrkNo2 != 0) {
                                wrkNo = wrkNo2;
                            }
                            staProtocol.setWorkNo(wrkNo);     // 工作号
                        }
                    }
 
                    Thread.sleep(100);
                    for (Integer staNo : staNos4) {
                        OperateResultExOne<byte[]> result5 = siemensS7Net.Read("DB" + staNo + ".22.0", (short) 2);
                        OperateResultExOne<byte[]> result6 = siemensS7Net.Read("DB" + staNo + ".250.0", (short) 2);
                        if (result5.IsSuccess && result6.IsSuccess) {
                            StaProtocol staProtocol = station.get(staNo);
                            short wrkNo1 = siemensS7Net.getByteTransform().TransInt16(result5.Content, 0);
                            short wrkNo2 = siemensS7Net.getByteTransform().TransInt16(result6.Content, 0);
                            short wrkNo = 0;
                            if (wrkNo1 != 0) {
                                wrkNo = wrkNo1;
                            }
                            if (wrkNo2 != 0) {
                                wrkNo = wrkNo2;
                            }
                            staProtocol.setWorkNo(wrkNo);     // 工作号
                        }
                    }
                }
                siemensS7Net.ConnectClose();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
}