From 389ed5b1fb5585e66c95e3891ff8b40e02fe1995 Mon Sep 17 00:00:00 2001 From: lsh <1> Date: 星期四, 07 三月 2024 14:08:53 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/model/protocol/StaProtocol.java | 8 ++ src/main/java/com/zy/asrs/entity/BasDevp.java | 16 +++++ src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 33 ++++++++++ src/main/java/com/zy/core/MainProcess.java | 4 + src/main/resources/mapper/BasDevpMapper.xml | 4 + src/main/java/com/zy/core/thread/SiemensDevpThread.java | 110 ++++++++++++++++++++++++++++++++++++ src/main/resources/application.yml | 2 7 files changed, 174 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/zy/asrs/entity/BasDevp.java b/src/main/java/com/zy/asrs/entity/BasDevp.java index 1e3d022..79125fd 100644 --- a/src/main/java/com/zy/asrs/entity/BasDevp.java +++ b/src/main/java/com/zy/asrs/entity/BasDevp.java @@ -214,6 +214,22 @@ @TableField("cart_pos") private Integer cartPos; + @ApiModelProperty(value= "") + @TableField("agv_start_pick") + private Integer agvStartPick; + + @ApiModelProperty(value= "") + @TableField("agv_target_pick") + private Integer agvTargetPick; + + @ApiModelProperty(value= "") + @TableField("agv_start_place") + private Integer agvStartPlace; + + @ApiModelProperty(value= "") + @TableField("agv_target_place") + private Integer agvTargetPlace; + public String getIoTime$(){ if (Cools.isEmpty(this.ioTime)){ 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 046a07a..98efc3c 100644 --- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java @@ -1132,7 +1132,38 @@ } } - //鑷姩瀹屾垚浠诲姟 + //agv鍙栨斁璐т换鍔″畬鎴� + public synchronized void autoCompleteAGV() { + List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>()); + for (BasDevp basDevp:basDevps){ + DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1); + StaProtocol staProtocol = devpThread.getStation().get(basDevp.getDevNo()); + if (staProtocol == null) { + continue; + } else { + staProtocol = staProtocol.clone(); + } + if (basDevp.getWrkNo()!=0){ + if (basDevp.getAgvTargetPick()!=0){//鍙栬揣 + staProtocol.setAgvTypeSign((short)0); + staProtocol.setStaNo(basDevp.getDevNo().shortValue()); + MessageQueue.offer(SlaveType.Devp, 1, new Task(4, staProtocol)); + }else if (basDevp.getAgvTargetPlace()!=0){ + staProtocol.setAgvTypeSign((short)1); + staProtocol.setStaNo(basDevp.getDevNo().shortValue()); + MessageQueue.offer(SlaveType.Devp, 1, new Task(4, staProtocol)); + } + }else { + if (basDevp.getAgvTargetPick()!=0){ + basDevp.setAgvStartPick(0); + basDevpService.updateById(basDevp); + }else if (basDevp.getAgvTargetPlace()!=0){ + basDevp.setAgvStartPlace(0); + basDevpService.updateById(basDevp); + } + } + } + } public synchronized void autoCompleteTask() { List<TaskWrk> taskWrks = taskWrkMapper.selectWorkingTask(); for (TaskWrk taskWrk : taskWrks) { diff --git a/src/main/java/com/zy/core/MainProcess.java b/src/main/java/com/zy/core/MainProcess.java index cbf409d..93c01fd 100644 --- a/src/main/java/com/zy/core/MainProcess.java +++ b/src/main/java/com/zy/core/MainProcess.java @@ -71,7 +71,9 @@ //鑷姩娲惧彂浠诲姟 // mainService.autoDistribute(); //鑷姩瀹屾垚浠诲姟 - //mainService.autoCompleteTask(); +// mainService.autoCompleteTask(); + //agv鍙栨斁璐у畬鎴� + mainService.autoCompleteAGV(); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/zy/core/model/protocol/StaProtocol.java b/src/main/java/com/zy/core/model/protocol/StaProtocol.java index a848f98..16bae8e 100644 --- a/src/main/java/com/zy/core/model/protocol/StaProtocol.java +++ b/src/main/java/com/zy/core/model/protocol/StaProtocol.java @@ -105,6 +105,12 @@ private Boolean upcontactErr = false; //椤跺崌鐢垫満鎺ヨЕ鍣ㄦ晠闅� + + + private Short agvStartPick; //鍏佽鍙栬揣 + private Short agvStartPlace; //鍏佽鏀捐揣 + private Short agvTypeSign; //鍏佽鏀捐揣 + private List<Integer> alarm; @@ -152,6 +158,8 @@ basDevp.setLocType3((short) 0); // 杞婚噸绫诲瀷{0:鏈煡,1:杞诲簱浣�,2:閲嶅簱浣峿 basDevp.setLocType1(high != low && low ? (short) 1 : (short) 2); basDevp.setInQty(inQty !=null ?(int)inQty : 0); + basDevp.setAgvStartPick(agvStartPick.intValue()); + basDevp.setAgvStartPlace(agvStartPlace.intValue()); return basDevp; } diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java index 5e9dc63..52c745a 100644 --- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java +++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java @@ -125,6 +125,11 @@ write((StaProtocol)task.getData()); read(); break; + // 鍐欐暟鎹� ID+鐩爣绔� + case 4: + writeAgvOk((StaProtocol)task.getData()); + read(); + break; /* case 3: write2((StaProtocol)task.getData()); read(); @@ -229,6 +234,34 @@ } } + OperateResultExOne<byte[]> resultAgvAndPlc = siemensS7Net.Read("DB102.0", (short) 30); + if (resultAgvAndPlc.IsSuccess) { + for (int i = 0; i < staNoSize; i++) { + int sign =(i+2)/2-1; + if ((i+2)%2!=0){ + Integer siteId = staNos.get(i); // 绔欑偣缂栧彿 + StaProtocol staProtocol = station.get(siteId); + if (null == staProtocol) { + staProtocol = new StaProtocol(); + staProtocol.setSiteId(siteId); + station.put(siteId, staProtocol); + } + staProtocol.setAgvStartPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6+4)); // 鍏佽鍙栬揣 + staProtocol.setAgvStartPlace((short)0); // 鍏佽鏀捐揣 + continue; + } + Integer siteId = staNos.get(i); // 绔欑偣缂栧彿 + StaProtocol staProtocol = station.get(siteId); + if (null == staProtocol) { + staProtocol = new StaProtocol(); + staProtocol.setSiteId(siteId); + station.put(siteId, staProtocol); + } + staProtocol.setAgvStartPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6)); // 鍏佽鍙栬揣 + staProtocol.setAgvStartPlace(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6 + 2)); // 鍏佽鏀捐揣 + } + } + if (slave.getId() == 1) { //鏉$爜 @@ -324,6 +357,83 @@ /** * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏� */ + private void writeAgvOk(StaProtocol staProtocol) throws InterruptedException { + if (null == staProtocol) { + return; + } + ArrayList<Integer> staNos = getStaNo(); + int index = staNos.indexOf(staProtocol.getSiteId()); + if (staProtocol.getAgvTypeSign()==0){ //0鍙栬揣 + switch (staProtocol.getSiteId()){ + case 100: + index=32; + break; + case 101: + index=34; + break; + case 102: + index=38; + break; + case 103: + index=40; + break; + case 104: + index=44; + break; + case 105: + index=46; + break; + case 106: + index=50; + break; + case 107: + index=52; + break; + default: + return; + } + }else { + switch (staProtocol.getSiteId()){ + case 100: + index=30; + break; + case 102: + index=36; + break; + case 104: + index=42; + break; + case 106: + index=48; + break; + default: + return; + } + } + + OperateResult write = null; + //浠诲姟涓嬪彂娆℃暟 + int writeCount = 0; + do { + write = siemensS7Net.Write("DB102." + index, true); // 浠诲姟瀹屾垚 + if(write.IsSuccess){ + writeCount=6; + }else { + writeCount++; + log.error("鍐欏叆杈撻�佺嚎鍙栨斁璐у畬鎴愬懡浠ゅ悗璇诲彇澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); + } + }while (writeCount<5); + + if (!write.IsSuccess) { + OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2}", slave.getId(), JSON.toJSON(staProtocol))); + log.error("鍐欏叆杈撻�佺嚎鍙栨斁璐у畬鎴愮珯鐐规暟鎹け璐ャ�傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={}", slave.getId(), JSON.toJSON(staProtocol)); + } else { + OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆� 杈撻�佺嚎鍛戒护涓嬪彂 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol))); + log.info("杈撻�佺嚎鍙栨斁璐у畬鎴愬懡浠や笅鍙戠爜鍨涘畬鎴� 缁欒緭閫佺嚎鍐欎换鍔″畬鎴� [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}", slave.getId(), JSON.toJSON(staProtocol)); + } + + + } private void write(StaProtocol staProtocol) throws InterruptedException { if (null == staProtocol) { return; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 52d457c..7367615 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -50,7 +50,7 @@ #url: 10.32.53.195:8080 # WMS绯荤粺ip # url: 10.210.157.109:8090 - url: 10.210.157.11:8080/wms + url: localhost:8080/wms # 鍏ュ簱浠诲姟鐢宠鎺ュ彛 #inboundTaskApplyPath: api/InterFace/inboundTaskApply # inboundTaskApplyPath: apis/inboundTaskApply diff --git a/src/main/resources/mapper/BasDevpMapper.xml b/src/main/resources/mapper/BasDevpMapper.xml index b00be22..06c6ac0 100644 --- a/src/main/resources/mapper/BasDevpMapper.xml +++ b/src/main/resources/mapper/BasDevpMapper.xml @@ -41,6 +41,10 @@ <result column="max_wt" property="maxWt" /> <result column="gross_wt" property="grossWt" /> <result column="cart_pos" property="cartPos" /> + <result column="agv_start_pick" property="agvStartPick" /> + <result column="agv_target_pick" property="agvTargetPick" /> + <result column="agv_start_place" property="agvStartPlace" /> + <result column="agv_target_place" property="agvTargetPlace" /> </resultMap> -- Gitblit v1.9.1