From c588ec9236ef644fe13af957920198bdcb4e05e8 Mon Sep 17 00:00:00 2001 From: lty <876263681@qq.com> Date: 星期六, 29 三月 2025 13:44:38 +0800 Subject: [PATCH] #输送线循环覆写由plc执行 --- src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 46 +++------- src/main/java/com/zy/core/MainProcess.java | 21 +++-- src/main/java/com/zy/core/thread/SiemensDevpThread.java | 89 ++++++++++++++++++++++ src/main/resources/application.yml | 1 src/main/java/com/zy/core/model/protocol/Cycle.java | 51 ++++++++++++ 5 files changed, 168 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java index 037ce7a..7c53b3c 100644 --- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java +++ b/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); diff --git a/src/main/java/com/zy/core/MainProcess.java b/src/main/java/com/zy/core/MainProcess.java index d0410f4..ed2bffa 100644 --- a/src/main/java/com/zy/core/MainProcess.java +++ b/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(); diff --git a/src/main/java/com/zy/core/model/protocol/Cycle.java b/src/main/java/com/zy/core/model/protocol/Cycle.java new file mode 100644 index 0000000..48d7ce9 --- /dev/null +++ b/src/main/java/com/zy/core/model/protocol/Cycle.java @@ -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; + } +} diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java index d731d3a..783e791 100644 --- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java +++ b/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("杈撻�佺嚎鍛戒护鍐欏叆鎴愬姛锛孭LC缂栧彿={}锛岀珯鐐规暟鎹�={}锛屽皾璇曟鏁�={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); + break; + } + + log.warn("杈撻�佺嚎鍛戒护鍐欏叆澶辫触锛孭LC缂栧彿={}锛岀珯鐐规暟鎹�={}锛屽皾璇曟鏁�={}", 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; + } + /** * 澶勭悊鍐欏叆澶辫触鐨勬儏鍐� */ diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index de218f1..212973e 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -46,6 +46,7 @@ wms: #杈撻�佺嚎鏆傚瓨鏁� count: 8 + maxCirle: 5 # 鏄惁寮�鍚笂鎶� start: true # WMS绯荤粺ip -- Gitblit v1.9.1