src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/core/MainProcess.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/core/model/protocol/Cycle.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/core/thread/SiemensDevpThread.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/application.yml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -159,31 +159,15 @@ StaProtocol staProtocol5 = getClonedStation(devpThread, staProtocol.getSiteId() - 1); if (staProtocol5 != null && (staProtocol5.isLoading() && (staProtocol5.getStaNo() == 107 || staProtocol5.getStaNo() == 109))) { short workNo = staProtocol5.getWorkNo(); // **先清零,等待 100ms** staProtocol5.setWorkNo((short) 0); staProtocol5.setStaNo((short) 0); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol5)); Thread.sleep(100); // **再写入目标值** staProtocol5.setWorkNo(workNo); staProtocol5.setStaNo((short) 112); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol5)); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, staProtocol5)); } } else { short workNo = staProtocol.getWorkNo(); // **先清零,等待 100ms** staProtocol.setWorkNo((short) 0); staProtocol.setStaNo((short) 0); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); Thread.sleep(100); // **再写入目标值** staProtocol.setWorkNo(workNo); staProtocol.setStaNo((short) 112); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, staProtocol)); } } } @@ -212,13 +196,13 @@ StaProtocol staProtocol = devpThread.getStation().get(112); StaProtocol staProtocol2 = devpThread.getStation().get(116); StaProtocol staProtocol3 = devpThread.getStation().get(117); if(Objects.equals(staProtocol3.getWorkNo(), staProtocol.getWorkNo()) && staProtocol.getWorkNo() != 0){ staProtocol.setWorkNo((short) 0); staProtocol.setStaNo((short) 0); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); Thread.sleep(100); // 让 PLC 识别变化 } // StaProtocol staProtocol3 = devpThread.getStation().get(117); // if(Objects.equals(staProtocol3.getWorkNo(), staProtocol.getWorkNo()) && staProtocol.getWorkNo() != 0){ // staProtocol.setWorkNo((short) 0); // staProtocol.setStaNo((short) 0); // MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); // Thread.sleep(100); // 让 PLC 识别变化 // } if (staProtocol == null || staProtocol.getWorkNo() == 0 || !staProtocol.isLoading() ) { continue; } @@ -234,18 +218,18 @@ continue; } // 先清零 // 先清零 short workNo = staProtocol.getWorkNo(); short oldStaNo = staProtocol.getStaNo(); staProtocol.setWorkNo((short) 0); staProtocol.setStaNo((short) 0); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); Thread.sleep(100); // 让 PLC 识别变化 // staProtocol.setWorkNo((short) 0); // staProtocol.setStaNo((short) 0); // MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); // Thread.sleep(100); // 让 PLC 识别变化 // 再写入目标站点 staProtocol.setWorkNo(workNo); staProtocol.setStaNo(Short.valueOf(taskWrk.getTargetPoint())); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, staProtocol)); Thread.sleep(200); log.info("Shifted from cycle station 112 to target {}, workNo: {}", taskWrk.getTargetPoint(), workNo); src/main/java/com/zy/core/MainProcess.java
@@ -27,6 +27,9 @@ // 频率 private int i = 0; @Value("${wms.maxCirle}") private Integer maxCount; /** * =====>> 开始工作 */ @@ -62,14 +65,16 @@ // mainService.outOfDevp(); // 其他 ===>> // 入出库模式切换函数 i++; if (i > 2) { //环形循环函数 mainService.shiftTargetToCyclePoint(); mainService.shiftCyclePointToTarget(); i = 0; } //环形循环函数 mainService.shiftTargetToCyclePoint(); mainService.shiftCyclePointToTarget(); // i++; // if (i > maxCount) { // //环形循环函数 // mainService.shiftTargetToCyclePoint(); // mainService.shiftCyclePointToTarget(); // i = 0; // } //自动派发任务 // mainService.autoDistribute(); src/main/java/com/zy/core/model/protocol/Cycle.java
New file @@ -0,0 +1,51 @@ package com.zy.core.model.protocol; public class Cycle implements Cloneable { // 站点编号 private Integer siteId; // 工作号 private Short workNo = 0; // 目标站 private Short staNo; public Cycle(Integer siteId, Short staNo) { this.siteId = siteId; this.staNo = staNo; } public Integer getSiteId() { return siteId; } public void setSiteId(Integer siteId) { this.siteId = siteId; } public Short getWorkNo() { return workNo; } public void setWorkNo(Short workNo) { this.workNo = workNo; } public Short getStaNo() { return staNo; } public void setStaNo(Short staNo) { this.staNo = staNo; } @Override public Cycle clone() { try { return (Cycle) super.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } return null; } } src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -24,6 +24,7 @@ import com.zy.core.enums.SlaveType; import com.zy.core.model.DevpSlave; import com.zy.core.model.Task; import com.zy.core.model.protocol.Cycle; import com.zy.core.model.protocol.StaProtocol; import lombok.Data; import lombok.extern.slf4j.Slf4j; @@ -132,7 +133,7 @@ break; // 写数据 ID+目标站 case 4: writeAgvOk((StaProtocol)task.getData()); writeCycle((StaProtocol)task.getData()); read(); break; /* case 3: @@ -544,6 +545,76 @@ handleWriteFailure(staProtocol, writeFlag); } private void writeCycle(StaProtocol staProtocol) throws InterruptedException { if (staProtocol == null) { return; } ArrayList<Integer> staNos = getStaNo(); int index = staNos.indexOf(staProtocol.getSiteId()); if (index == -1) { log.error("站点编号 {} 不在已知列表中,无法写入任务!", staProtocol.getSiteId()); return; } int writeCount = 0; // 任务下发尝试次数 boolean writeFlag = false; // 任务下发成功标记 String plcAddressWorkNo = ""; String plcAddressStaNo = "" ; switch (staProtocol.getSiteId()){ case 105: plcAddressWorkNo = "DB73." + 0; plcAddressStaNo = "DB73." + 4; break; case 106: plcAddressWorkNo = "DB73." + 6; plcAddressStaNo = "DB73." + (6 + 4); break; case 108: plcAddressWorkNo = "DB73." + 2 * 6; plcAddressStaNo = "DB73." + (2 * 6 + 4); break; case 110: plcAddressWorkNo = "DB73." + 3 * 6; plcAddressStaNo = "DB73." + (3 * 6 + 4); break; case 112: plcAddressWorkNo = "DB73." + 4 * 6; plcAddressStaNo = "DB73." + (4 * 6 + 4); break; } // String plcAddressWorkNo = "DB100." + index * 6; // String plcAddressStaNo = "DB100." + (index * 6 + 4); while (writeCount < 5) { // **读取当前PLC状态,避免不必要的写入** OperateResultExOne<byte[]> readResult = siemensS7Net.Read(plcAddressWorkNo, (short) 6); if (readResult.IsSuccess) { int currentWorkNo = siemensS7Net.getByteTransform().TransInt32(readResult.Content, 0); short currentStaNo = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 4); if (currentWorkNo == staProtocol.getWorkNo().intValue() && currentStaNo == staProtocol.getStaNo()) { log.info("站点 {} 当前状态已匹配,无需重复写入", staProtocol.getSiteId()); return; } } // **写入新任务** if (writeTaskToPLC(plcAddressWorkNo, plcAddressStaNo, staProtocol)) { writeFlag = true; log.info("输送线命令写入成功,PLC编号={},站点数据={},尝试次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); break; } log.warn("输送线命令写入失败,PLC编号={},站点数据={},尝试次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); writeCount++; } // **写入失败处理** handleWriteFailure(staProtocol, writeFlag); } /** * 清零 PLC 数据并验证清零是否成功 */ @@ -584,6 +655,22 @@ return false; } private boolean writeTaskToPLC(String plcAddressWorkNo, String plcAddressStaNo, Cycle cycle) throws InterruptedException { OperateResult writeResult1 = siemensS7Net.Write(plcAddressWorkNo, cycle.getWorkNo().intValue()); OperateResult writeResult2 = siemensS7Net.Write(plcAddressStaNo, cycle.getStaNo()); if (writeResult1.IsSuccess && writeResult2.IsSuccess) { Thread.sleep(200); // 等待 PLC 识别新值 OperateResultExOne<byte[]> readResult = siemensS7Net.Read(plcAddressWorkNo, (short) 6); if (readResult.IsSuccess) { int workNo = siemensS7Net.getByteTransform().TransInt32(readResult.Content, 0); short staNo = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 4); return workNo == cycle.getWorkNo().intValue() && staNo == cycle.getStaNo(); } } return false; } /** * 处理写入失败的情况 */ src/main/resources/application.yml
@@ -46,6 +46,7 @@ wms: #输送线暂存数 count: 8 maxCirle: 5 # 是否开启上报 start: true # WMS系统ip