zhoushihao
2025-05-21 82332c7f698c23057a91b850584f8d89f124f138
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
package com.mes.job;
 
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.service.MiloService;
import com.mes.hollow.entity.vo.HollowGlassFormulaVO;
import com.mes.hollow.service.HollowFormulaDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author SNG-015
 */
@Component
@Slf4j
public class OpcHollowRemoveTask {
    @Resource
    private HollowFormulaDetailsService hollowFormulaDetailsService;
    @Resource
    private OpcPlcStorageCageHollowTask opcPlcStorageCageHollowTask;
 
    @Autowired(required = false)
    MiloService miloService;
 
    /**
     * 收到除膜机请求及玻璃id
     *
     * @throws Exception
     */
    @Scheduled(fixedDelay = 1000)
    public void hollowRemoveTaskOne() throws Exception {
        hollowRemoveChildTask("CMJ1.CMJ1.");
    }
 
    @Scheduled(fixedDelay = 1000)
    public void hollowRemoveTaskTwo() throws Exception {
        hollowRemoveChildTask("CMJ2.CMJ2.");
    }
 
    private void hollowRemoveChildTask(String cell) throws Exception {
        ReadWriteEntity requestEntity = miloService.readFromOpcUa(cell + "mesControl");
        if ("0".equals(requestEntity.getValue() + "")) {
            log.info("当前除膜机为单机状态");
            return;
        }
        int request = Integer.parseInt(requestEntity.getValue() + "");
        int flagRequest = request & 3;
        ReadWriteEntity glassIdEntity = miloService.readFromOpcUa(cell + "glassId");
        log.info("除膜{}获取当前的信号为:{},玻璃id:{}", cell, flagRequest, glassIdEntity);
        if (flagRequest != 3) {
            log.info("当前未收到请求玻璃id数据,结束任务");
            return;
        }
 
        log.info("除膜{}获取当前的玻璃id:{}", cell, glassIdEntity);
        if (null == glassIdEntity.getValue() || StringUtils.isBlank(glassIdEntity.getValue() + "")) {
            log.info("当前未收到玻璃id数据,结束任务");
            return;
        }
        log.info("当前需要除膜的玻璃id为:{}", glassIdEntity.getValue() + "");
        //按照玻璃id获取对应的任务id
        HollowGlassFormulaVO detailsVO = hollowFormulaDetailsService.queryFormulaDetailsByGlassId(glassIdEntity.getValue() + "", null, null);
        if (null == detailsVO) {
            log.info("玻璃id不存在,请检查数据");
            return;
        }
        //按照任务id获取对应的配方信息
 
        List<ReadWriteEntity> ualist = new ArrayList<>();
        List<ReadWriteEntity> wordlist = new ArrayList<>();
        log.info("除膜{}获取玻璃{},是否除膜:{}", cell, glassIdEntity.getValue(), detailsVO.getFilmRemove());
        if (detailsVO.getFilmRemove() == 0) {
            // 10111011
            int sendId = request & 63;
            sendId = sendId + 4;
            wordlist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "mesControl", sendId));
        } else {
            // 先将对应的位置为0,获得请求的玻璃数据, 然后将对应位值     110111011
            int sendId = request & 63;
            sendId = sendId + 4 + 64;
            wordlist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "mesControl", sendId));
            ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "glassTop", detailsVO.getTopRemove()));
            ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "glassBottom", detailsVO.getBottomRemove()));
            ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "glassLeft", detailsVO.getLeftRemove()));
            ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "glassRight", detailsVO.getRightRemove()));
        }
        ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "thickness", (int) (detailsVO.getThickness() * 10)));
        ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "firstLength", (int) (Math.max(detailsVO.getWidth(), detailsVO.getHeight())) * 10));
        ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "secondLength", (int) (Math.min(detailsVO.getWidth(), detailsVO.getHeight())) * 10));
        miloService.writeToOpcWord(wordlist);
        miloService.writeToOpcUa(ualist);
        return;
    }
 
    /**
     * 收到除膜机ID接收完成开始执行任务
     *
     * @throws Exception
     */
    @Scheduled(fixedDelay = 1000)
    public void finishHollowRemoveOneTask() throws Exception {
        finishHollowRemoveChildTask("CMJ1.CMJ1.");
    }
 
    @Scheduled(fixedDelay = 1000)
    public void finishHollowRemoveTwoTask() throws Exception {
        finishHollowRemoveChildTask("CMJ2.CMJ2.");
    }
 
    public void finishHollowRemoveChildTask(String cell) throws Exception {
        ReadWriteEntity requestEntity = miloService.readFromOpcUa(cell + "mesControl");
        int request = Integer.parseInt(requestEntity.getValue() + "");
        int flagRequest = request & 9;
        if (flagRequest != 9) {
            log.info("当前未收到除膜机ID接收完成信号,结束任务");
            return;
        }
        //向电气发送清楚信号
        int sendId = request & 251;
        log.info("{}收到除膜机ID接收完成信号,将写入数据完成置0,发送数据为:{}", cell, sendId);
        List<ReadWriteEntity> list = new ArrayList<>();
        list.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "mesControl", sendId));
        miloService.writeToOpcWord(list);
    }
 
}