自动化立体仓库 - WCS系统
Junjie
2023-11-29 35fac40cfc0d636479bde094391e6f237b3116d4
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -19,6 +19,7 @@
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.CommandStatusType;
import com.zy.core.enums.IoModeType;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.DevpSlave;
@@ -223,7 +224,7 @@
                staProtocol.setOutEnable(status[3]);// 可出
                staProtocol.setEmptyMk(status[4]);  // 空板信号
                staProtocol.setFullPlt(status[5]);  // 满托盘
                staProtocol.setHigh(status[6]);     // 高库位
                staProtocol.setCar(status[6]);     // 是否有车
                staProtocol.setLow(status[7]);      // 低库位
                if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
@@ -239,7 +240,7 @@
            OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.102",(short)60);
            if (result2.IsSuccess) {
                for (int i = 0; i < 6; i++) {
                    String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8");
                    String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*10,8, "UTF-8");
                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
                    if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
                        barcodeThread.setBarcode(barcode);
@@ -423,22 +424,24 @@
        CommandInfoLogService commandInfoLogService = SpringUtils.getBean(CommandInfoLogService.class);
        CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
        CommandInfo commandInfo = commandInfoService.selectById(staProtocol.getCommandId());
        CommandInfoLog commandInfoLog = new CommandInfoLog();
        if (commandInfo != null) {
            commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
            commandInfoLog.setId(null);
        }else {
            Date now = new Date();
            commandInfoLog.setCommand(JSON.toJSONString(staProtocol));
            commandInfoLog.setCommandStatus(3);
            commandInfoLog.setStartTime(now);
            commandInfoLog.setExecuteTime(now);
            commandInfoLog.setCompleteTime(now);
            commandInfoLog.setDevice(SlaveType.Devp.toString());
            commandInfoLog.setWrkNo(9999);
            commandInfoLog.setTaskNo("9999");
            commandInfoLog.setCommandDesc("手动命令");
        }
        CommandInfoLog commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
        commandInfoLog.setId(null);
//        CommandInfoLog commandInfoLog = new CommandInfoLog();
//        if (commandInfo != null) {
//            commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
//            commandInfoLog.setId(null);
//        }else {
//            Date now = new Date();
//            commandInfoLog.setCommand(JSON.toJSONString(staProtocol));
//            commandInfoLog.setCommandStatus(3);
//            commandInfoLog.setStartTime(now);
//            commandInfoLog.setExecuteTime(now);
//            commandInfoLog.setCompleteTime(now);
//            commandInfoLog.setDevice(SlaveType.Devp.toString());
//            commandInfoLog.setWrkNo(9999);
//            commandInfoLog.setTaskNo("9999");
//            commandInfoLog.setCommandDesc("手动命令");
//        }
        OperateResult writeResult;
        //任务下发次数
@@ -447,9 +450,6 @@
        boolean writeFlag = false;
        while(writeCount < 5){
            writeResult = siemensS7Net.Write("DB100." + index*4, array);    // 工作号、目标站
            //更新指令日志
            commandInfoLog.setDeviceLog("指令下发成功");
            commandInfoLogService.insert(commandInfoLog);
            if(writeResult.IsSuccess){
                Thread.sleep(200);
@@ -461,12 +461,39 @@
                        //任务命令写入成功
                        writeFlag = true;
                        log.info("写入输送线命令后返回成功,并且回读成功。输送线plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
                        Date now = new Date();
                        //更新指令状态
                        commandInfo.setCommandStatus(CommandStatusType.COMPLETE.id);//输送线直接完成状态
                        commandInfo.setExecuteTime(now);
                        commandInfo.setCompleteTime(now);
                        commandInfoService.updateById(commandInfo);
                        //更新指令日志
                        commandInfoLog.setDeviceLog("指令下发成功");
                        commandInfoLog.setCommandStatus(CommandStatusType.COMPLETE.id);//输送线直接完成状态
                        commandInfoLog.setExecuteTime(now);
                        commandInfoLog.setCompleteTime(now);
                        commandInfoLogService.insert(commandInfoLog);
                        //更新任务步序
                        TaskWrkService taskWrkService = SpringUtils.getBean(TaskWrkService.class);
                        TaskWrk taskWrk = taskWrkService.selectByWrkNo(staProtocol.getWorkNo().intValue());
                        if (taskWrk != null) {
                            taskWrk.setCommandStep(taskWrk.getCommandStep() + 1);//更新指令步序
                            taskWrkService.updateById(taskWrk);
                        }
                        break;
                    } else {//返回结果是成功了,但是真实值不相同
                        writeCount++;
                        OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线命令后返回成功,但是读取任务值不一致。输送线plc编号={1},站点数据={2},写入次数={3}",
                                slave.getId(), JSON.toJSON(staProtocol),writeCount));
                        log.error("写入输送线命令后返回成功,但是读取任务值不一致。输送线plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
                        //更新指令日志
                        commandInfoLog.setDeviceLog("指令下发失败");
                        commandInfoLogService.insert(commandInfoLog);
                    }
                } else {
                    writeCount++;