zhoushihao
2024-07-23 be032257d1562085b507496140dd3551570962e0
hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/PlcStorageCageTask.java
@@ -85,7 +85,14 @@
    @Value("${mes.glassGap}")
    private Integer glassGap;
    @Scheduled(fixedDelay = 500)
    @Value("${mes.xMaxSize}")
    private Integer xMaxSize;
    private String d01GlassId = "";
    private String d04GlassId = "";
    @Scheduled(fixedDelay = 300)
    public void plcToHomeEdgScan() {
        Date startDate = new Date();
        log.info("大理片笼扫码任务开始执行时间:{}", startDate);
@@ -114,17 +121,23 @@
        }
        //按照线路及玻璃id获取相邻两块玻璃 卧转立上的玻璃:  状态为0不操作(D01送片,0不操作,1允许送片),请求字为1, (02玻璃id为空或者卧转立未启动)
        if (!REQUEST_WORD.equals(mesD01Value) && REQUEST_WORD.equals(d01ToMES) && (StringUtils.isBlank(d02State) || !REQUEST_WORD.equals(d03State))) {
            judgeGlassTypeStatus(d01Id, Const.A09_OUT_TARGET_POSITION, mesD01Address);
            if (!d01GlassId.equals(d01Id)) {
                judgeGlassTypeStatus(d01Id, Const.A09_OUT_TARGET_POSITION, mesD01Address);
                d01GlassId = d01Id;
            }
        }
//        状态为0不操作(D01送片,0不操作,1允许送片),请求字为1, 卧转立未启动
        if (!REQUEST_WORD.equals(mesD04Value) && REQUEST_WORD.equals(d04ToMES) && !REQUEST_WORD.equals(d05State)) {
            judgeGlassTypeStatus(d04Id, Const.A10_OUT_TARGET_POSITION, mesD04Address);
            if (!d04GlassId.equals(d04Id)) {
                judgeGlassTypeStatus(d04Id, Const.A10_OUT_TARGET_POSITION, mesD04Address);
                d04GlassId = d04Id;
            }
        }
        Date endDate = new Date();
        log.info("大理片笼扫码任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime());
    }
    @Scheduled(fixedDelay = 500)
    @Scheduled(fixedDelay = 300)
    public void plcToHomeEdgFreeCarTask() {
        Date startDate = new Date();
        log.info("大理片笼空车进片任务开始执行时间:{}", startDate);
@@ -231,11 +244,16 @@
        log.info("大理片笼空车进片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime());
    }
    @Scheduled(fixedDelay = 500)
    @Scheduled(fixedDelay = 300)
    public void plcToHomeEdgOutTask() {
        Date startDate = new Date();
        log.info("大理片笼空车进片任务开始执行时间:{}", startDate);
        PlcParameterObject plcMesObject = S7object.getinstance().PlcMesObject;
        String e02State = plcMesObject.getPlcParameter("E02State").getAddress();
        if (REQUEST_WORD.equals(e02State)) {
            log.info("出片忙碌,结束出片任务");
            return;
        }
        String mesToPLCAddress = plcMesObject.getPlcParameter("MESToPLC").getAddress();
        List<BigStorageCageOutTask> outingList = bigStorageCageOutTaskService.list(new LambdaQueryWrapper<BigStorageCageOutTask>().eq(BigStorageCageOutTask::getTaskState, Const.BIG_STORAGE_OUT_NEW));
        Assert.isTrue(CollectionUtils.isEmpty(outingList), "有正在执行出片的任务,结束当前出片线程");
@@ -299,10 +317,18 @@
                    List<BigStorageCageDetails> list = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>()
                            .eq(BigStorageCageDetails::getSlot, first.getSlot()).eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN));
                    List<BigStorageCageOutTask> outTasks = list.stream().map(e -> new BigStorageCageOutTask(e.getGlassId(), first.getSlot(), second.getSlot(),
                            slotWidth, 0, 0, 1)).collect(Collectors.toList());
                            e.getWidth() * 10, e.getHeight() * 10, 0, 0, 1)).collect(Collectors.toList());
                    bigStorageCageOutTaskService.saveBatch(outTasks);
                    S7object.getinstance().plccontrol.writeWord(mesToPLCAddress, 1);
                    log.info("已向plc发送出片任务确认,地址为:{}", mesToPLCAddress);
                    //向plc写入确认字
                    int returnData = 0;
                    int count = 1;
                    while (returnData == 0) {
                        log.info("已向plc第{}次送协议", count);
                        S7object.getinstance().plccontrol.writeWord(mesToPLCAddress, 1);
                        returnData = S7object.getinstance().plccontrol.readWord(mesToPLCAddress, 1).get(0);
                        log.info("已向plc第{}次发送出片任务确认,地址为:{},写入的内容为{}", count++, mesToPLCAddress, returnData);
                    }
                    Date endDate = new Date();
                    log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime());
                    return;
@@ -311,7 +337,7 @@
        }
    }
    @Scheduled(fixedDelay = 500)
    @Scheduled(fixedDelay = 300)
    public void updateOutGlassStateTask() {
        Date startDate = new Date();
        log.info("1、大理片笼出片完成后更新大理片笼数据任务开始执行时间:{}", startDate);
@@ -340,7 +366,7 @@
    /**
     * 处理破损表任务
     */
    @Scheduled(fixedDelay = 500)
    @Scheduled(fixedDelay = 300)
    public void dealDamageTask() {
        Date startDate = new Date();
        log.info("大理片笼破损玻璃清除任务开始执行时间:{}", startDate);
@@ -450,7 +476,15 @@
        }
        //向plc发送进片确认
        if (flag) {
            S7object.getinstance().plccontrol.writeWord(mesAddress, 1);
            //向plc写入确认字
            int returnData = 0;
            int count = 1;
            while (returnData == 0) {
                S7object.getinstance().plccontrol.writeWord(mesAddress, 1);
                returnData = S7object.getinstance().plccontrol.readWord(mesAddress, 1).get(0);
                log.info("进卧转立第{}次发送确认字完成,地址为:{},写入的内容为{}", count++, mesAddress, returnData);
            }
        }
        //记录无法放下玻璃,后续判断启动
        return flag;
@@ -557,8 +591,13 @@
            s7control.writeWord(plcMesObject.getPlcParameter("StartAddToImport" + i).getAddress(), taskList.get(i - 1).getLine());
            s7control.writeWord(plcMesObject.getPlcParameter("TargetAddToImport" + i).getAddress(), taskList.get(i - 1).getTargetSlot());
        }
        s7control.writeWord(outLine, 2);
        log.info("送片任务已发送完成,任务线路为:{},启动地址为{},确认字为{}", line, outLine, 2);
        int returnData = 0;
        int count = 1;
        while (returnData == 0) {
            s7control.writeWord(outLine, 2);
            returnData = s7control.readWord(outLine, 1).get(0);
            log.info("已向plc第{}次发送出片任务确认,地址为:{},写入的内容为{}", count++, outLine, returnData);
        }
    }
    private <T extends BigStorageCageBaseInfo> Boolean computeOutGlassInfo(List<T> list, Boolean isTempering, String mesToPLCAddress) {
@@ -566,17 +605,25 @@
        List<BigStorageCageOutTask> bigStorageCageOutTaskList = new ArrayList<>();
        //打车剩余尺寸
        Integer remainWidth = carWidth;
        int maxX = 0;
        for (T e : list) {
            if (bigStorageCageOutTaskList.size() >= outCarMaxSize || e.getWidth() > remainWidth) {
                break;
            }
            remainWidth = remainWidth - (int) e.getWidth() - glassGap;
            if (isTempering) {
                bigStorageCageOutTaskList.add(new BigStorageCageOutTask(e.getGlassId(), e.getSlot(), Const.TEMPERING_OUT_TARGET_POSITION,
                        (int) e.getWidth() * 10, 0, 0, 1));
                int minLength = Math.min((int) e.getWidth(), (int) e.getHeight());
                if (maxX + minLength <= xMaxSize) {
                    bigStorageCageOutTaskList.add(new BigStorageCageOutTask(e.getGlassId(), e.getSlot(), Const.TEMPERING_OUT_TARGET_POSITION,
                            e.getWidth() * 10, e.getHeight() * 10, 0, 0, 1));
                    maxX = Math.max(maxX, e.getXCoordinate());
                } else {
                    break;
                }
            } else {
                bigStorageCageOutTaskList.add(new BigStorageCageOutTask(e.getGlassId(), e.getSlot(), Const.ARTIFICIAL_OUT_TARGET_POSITION,
                        (int) e.getWidth() * 10, 0, 0, 1));
                        e.getWidth() * 10, e.getHeight(), 0, 0, 1));
            }
        }
@@ -590,8 +637,14 @@
                .in(BigStorageCageDetails::getGlassId, glassIds));
        //更新笼子内格子的剩余尺寸
        updateSlotRemain(list, glassIds);
        S7object.getinstance().plccontrol.writeWord(mesToPLCAddress, 1);
        log.info("已向plc发送出片任务确认,地址为:{}", mesToPLCAddress);
        int returnData = 0;
        int count = 1;
        while (returnData == 0) {
            S7object.getinstance().plccontrol.writeWord(mesToPLCAddress, 1);
            returnData = S7object.getinstance().plccontrol.readWord(mesToPLCAddress, 1).get(0);
            log.info("已向plc第{}次发送出片任务确认,地址为:{},写入的内容为{}", count++, mesToPLCAddress, returnData);
        }
        return Boolean.TRUE;
    }