From ff1be9fa2dba6eaffc449d09e62998348ea3b830 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 19 九月 2023 08:00:36 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/LiftThread.java | 109 +++++++++++++++------
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 44 +++++++-
src/main/java/com/zy/core/model/LiftSlave.java | 27 -----
src/main/java/com/zy/core/model/protocol/LiftStaProtocol.java | 87 +++++++++++++++++
4 files changed, 199 insertions(+), 68 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 d49cd79..099b310 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -2,6 +2,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
@@ -783,15 +784,44 @@
public boolean shuttleOutExecuteStep1(WrkMast wrkMast) {
//21.鐢熸垚鍑哄簱浠诲姟 => 22.灏忚溅鎼繍涓�
if (wrkMast.getWrkSts() == 21) {
- //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
- BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getLiftNo());
- if (targetBasDevp == null) {
- return false;//缂哄皯绔欑偣淇℃伅
+ EntityWrapper<StaDesc> wrapper = new EntityWrapper<>();
+ wrapper.eq("type_no", wrkMast.getIoType());//璺緞绫诲瀷
+ wrapper.eq("stn_no", wrkMast.getStaNo());//鍑哄簱绔欑偣缂栧彿
+ StaDesc staDesc = staDescService.selectOne(wrapper);
+ if (staDesc == null) {
+ return false;//鍑哄簱璺緞涓嶅瓨鍦�
}
- if (targetBasDevp.getOutEnable().equals("N")) {
- return false;//绔欑偣涓嶅彲鍑�
+ //鑾峰彇鍑哄簱绔欑偣
+ BasDevp basDevp = basDevpService.selectById(wrkMast.getStaNo());
+ if (basDevp == null) {
+ return false;//鍑哄簱绔欑偣涓嶅瓨鍦�
}
+
+ if (!basDevp.getOutEnable().equals("Y")) {
+ return false;//鍑哄簱绔欑偣涓嶅彲鍑�
+ }
+
+ //鍒ゆ柇鍚勬ゼ灞傚唴閮ㄨ緭閫佺珯鐐规槸鍚︾┖闂叉棤鐗�
+ LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, basDevp.getLiftNo());
+ if (liftThread == null) {
+ return false;
+ }
+ //鑾峰彇鎻愬崌鏈虹珯鐐筶ist
+ List<LiftStaProtocol> liftStaProtocols = liftThread.getLiftStaProtocols();
+ if (liftStaProtocols.isEmpty()) {
+ return false;
+ }
+
+ for (LiftStaProtocol liftStaProtocol : liftStaProtocols) {
+ //鍒ゆ柇褰撳墠鍑哄簱浠诲姟瀵瑰簲妤煎眰鐨勬彁鍗囨満绔欑偣鐘舵��
+ if (liftStaProtocol.getLev() == Utils.getLev(wrkMast.getSourceLocNo())) {
+ if (liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && !liftStaProtocol.getHasTray()) {
+ return false;//绔欑偣蹇呴』鑷姩銆佺┖闂层�佹病鏈夋墭鐩�
+ }
+ }
+ }
+
if (wrkMast.getShuttleNo() == null) {//娌℃湁缁戝畾灏忚溅锛岃繘琛岃皟搴�
shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄥ簱浣嶈繘琛屽彇璐�
@@ -823,7 +853,7 @@
}
//灏忚溅宸叉姷杈捐揣鐗╀綅缃紝杩涜鎼繍璐х墿
- NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), targetBasDevp.getLocNo());
+ NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), null);
if (result == null) {//鍑哄簱璺緞璁$畻澶辫触
return false;
}
diff --git a/src/main/java/com/zy/core/model/LiftSlave.java b/src/main/java/com/zy/core/model/LiftSlave.java
index 8d66ecf..f431b96 100644
--- a/src/main/java/com/zy/core/model/LiftSlave.java
+++ b/src/main/java/com/zy/core/model/LiftSlave.java
@@ -11,12 +11,6 @@
@Data
public class LiftSlave extends Slave {
- // 鎺�
- private Integer row;
-
- // 鍒�
- private Integer bay;
-
//鎻愬崌鏈虹珯鐐�
private List<Sta> sta = new ArrayList<>();
@@ -29,27 +23,6 @@
// 灞�
private Integer lev;
- }
-
- //鑾峰彇鎻愬崌鏈哄簱浣嶅彿
- public String getLiftLocNo(Integer lev) {
- StringBuffer sb = new StringBuffer();
- if (row < 10) {
- sb.append("0");
- }
- sb.append(row);
-
- if (bay < 10) {
- sb.append("00");
- } else if (bay < 100) {
- sb.append("0");
- }
- sb.append(bay);
- if (lev < 10) {
- sb.append("0");
- }
- sb.append(lev);
- return sb.toString();
}
}
diff --git a/src/main/java/com/zy/core/model/protocol/LiftStaProtocol.java b/src/main/java/com/zy/core/model/protocol/LiftStaProtocol.java
new file mode 100644
index 0000000..27feebb
--- /dev/null
+++ b/src/main/java/com/zy/core/model/protocol/LiftStaProtocol.java
@@ -0,0 +1,87 @@
+package com.zy.core.model.protocol;
+
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * 鎻愬崌鏈鸿緭閫佺珯鐐�
+ */
+@Slf4j
+@Data
+public class LiftStaProtocol {
+
+ /**
+ * 绔欑偣鍙�
+ */
+ private Integer staNo;
+
+ /**
+ * 妯″紡
+ */
+ private Boolean model;
+
+ /**
+ * 蹇欓棽
+ */
+ private Boolean busy;
+
+ /**
+ * 鍓嶈秴闄�
+ */
+ private Boolean frontOverrun;
+
+ /**
+ * 鍚庤秴闄�
+ */
+ private Boolean backOverrun;
+
+ /**
+ * 宸﹁秴闄�
+ */
+ private Boolean leftOverrun;
+
+ /**
+ * 鍙宠秴闄�
+ */
+ private Boolean rightOverrun;
+
+ /**
+ * 瓒呴珮
+ */
+ private Boolean overHeight;
+
+ /**
+ * 瓒呴噸
+ */
+ private Boolean overWeight;
+
+ /**
+ * 鏈夋墭鐩�
+ */
+ private Boolean hasTray;
+
+ /**
+ * 鏈夊皬杞�
+ */
+ private Boolean hasCar;
+
+ /**
+ * 璁惧鏁呴殰
+ */
+ private Boolean deviceError;
+
+ /**
+ * 褰撳墠鎵ц浠诲姟鍙�
+ */
+ private Short taskNo;
+ /**
+ * 宸插畬鎴愮殑浠诲姟鍙�
+ */
+ private Short completeTaskNo;
+
+ /**
+ * 灞�
+ */
+ private Integer lev;
+
+}
diff --git a/src/main/java/com/zy/core/thread/LiftThread.java b/src/main/java/com/zy/core/thread/LiftThread.java
index 3e0bafd..971b4ff 100644
--- a/src/main/java/com/zy/core/thread/LiftThread.java
+++ b/src/main/java/com/zy/core/thread/LiftThread.java
@@ -1,9 +1,7 @@
package com.zy.core.thread;
-import HslCommunication.Core.Transfer.DataFormat;
import HslCommunication.Core.Types.OperateResult;
import HslCommunication.Core.Types.OperateResultExOne;
-import HslCommunication.ModBus.ModbusTcpNet;
import HslCommunication.Profinet.Siemens.SiemensPLCS;
import HslCommunication.Profinet.Siemens.SiemensS7Net;
import com.alibaba.fastjson.JSON;
@@ -12,23 +10,19 @@
import com.core.exception.CoolException;
import com.zy.asrs.entity.BasLift;
import com.zy.asrs.entity.BasLiftOpt;
-import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.mapper.WrkMastMapper;
import com.zy.asrs.service.BasLiftOptService;
import com.zy.asrs.service.BasLiftService;
-import com.zy.asrs.utils.Utils;
-import com.zy.common.utils.CommonUtils;
import com.zy.common.utils.RedisUtil;
-import com.zy.core.DevpThread;
import com.zy.core.News;
import com.zy.core.ThreadHandler;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
-import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.*;
import com.zy.core.model.LiftSlave;
import com.zy.core.model.Task;
import com.zy.core.model.command.*;
+import com.zy.core.model.protocol.LiftStaProtocol;
import com.zy.core.model.protocol.LiftProtocol;
import com.zy.core.model.protocol.StaProtocol;
import lombok.Data;
@@ -50,10 +44,20 @@
private LiftSlave slave;
private LiftProtocol liftProtocol;
private RedisUtil redisUtil;
+ private List<LiftStaProtocol> liftStaProtocols = new ArrayList<>();
public LiftThread(LiftSlave slave,RedisUtil redisUtil) {
this.slave = slave;
this.redisUtil = redisUtil;
+
+ //鍒濆鍖栫珯鐐�
+ for (LiftSlave.Sta sta : this.slave.getSta()) {
+ LiftStaProtocol liftStaProtocol = new LiftStaProtocol();
+ liftStaProtocol.setStaNo(sta.getStaNo());//绔欑偣鍙�
+ liftStaProtocol.setLev(sta.getLev());//绔欑偣妤煎眰
+ liftStaProtocols.add(liftStaProtocol);
+ }
+
}
@Override
@@ -136,50 +140,47 @@
private void readStatus() {
try {
- OperateResultExOne<byte[]> result = siemensS7Net.Read("M100.0", (short) 28);
- if (result.IsSuccess) {
+ //鑾峰彇鎻愬崌鏈烘暟鎹�
+ OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB4.0", (short) 10);
+ if (result1.IsSuccess) {
if (null == liftProtocol) {
liftProtocol = new LiftProtocol();
liftProtocol.setLiftNo(slave.getId().shortValue());
}
-
- //----------璇诲彇鎻愬崌鏈虹姸鎬�-----------
- //鑾峰彇鏁版嵁
- byte[] content = result.Content;
+ //璇诲彇4.0-4.7鏁版嵁
+ boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result1.Content, 0, 1);
+ //璇诲彇5.0-5.7鏁版嵁
+ boolean[] status2 = siemensS7Net.getByteTransform().TransBool(result1.Content, 1, 1);
//妯″紡
- liftProtocol.setModel(siemensS7Net.getByteTransform().TransBool(content, 0));
+ liftProtocol.setModel(status1[0]);
//蹇欓棽
- liftProtocol.setBusy(siemensS7Net.getByteTransform().TransBool(content, 1));
+ liftProtocol.setBusy(status1[1]);
//鍓嶈秴闄�
- liftProtocol.setFrontOverrun(siemensS7Net.getByteTransform().TransBool(content, 7));
+ liftProtocol.setFrontOverrun(status1[4]);
//鍚庤秴闄�
- liftProtocol.setBackOverrun(siemensS7Net.getByteTransform().TransBool(content, 8));
+ liftProtocol.setBackOverrun(status1[5]);
//宸﹁秴闄�
- liftProtocol.setLeftOverrun(siemensS7Net.getByteTransform().TransBool(content, 9));
+ liftProtocol.setLeftOverrun(status1[6]);
//鍙宠秴闄�
- liftProtocol.setRightOverrun(siemensS7Net.getByteTransform().TransBool(content, 10));
+ liftProtocol.setRightOverrun(status1[7]);
//瓒呴珮
- liftProtocol.setOverHeight(siemensS7Net.getByteTransform().TransBool(content, 11));
+ liftProtocol.setOverHeight(status2[0]);
//瓒呴噸
- liftProtocol.setOverWeight(siemensS7Net.getByteTransform().TransBool(content, 12));
+ liftProtocol.setOverWeight(status2[1]);
//鏈夋墭鐩�
- liftProtocol.setHasTray(siemensS7Net.getByteTransform().TransBool(content, 16));
+ liftProtocol.setHasTray(status2[5]);
//鏈夊皬杞�
- liftProtocol.setHasCar(siemensS7Net.getByteTransform().TransBool(content, 17));
+ liftProtocol.setHasCar(status2[6]);
//璁惧鏁呴殰
- liftProtocol.setDeviceError(siemensS7Net.getByteTransform().TransBool(content, 18));
+ liftProtocol.setDeviceError(status2[7]);
//浠诲姟鍙�
- liftProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt16(content, 19));
- //浠诲姟鍦板潃
- liftProtocol.setTaskAddress(siemensS7Net.getByteTransform().TransInt16(content, 21));
+ liftProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt16(result1.Content, 2));
//鐩殑鍦板潃
- liftProtocol.setDistAddress(siemensS7Net.getByteTransform().TransInt16(content, 21));
+ liftProtocol.setDistAddress(siemensS7Net.getByteTransform().TransInt16(result1.Content, 4));
//宸插畬鎴愪换鍔″彿
- liftProtocol.setCompleteTaskNo(siemensS7Net.getByteTransform().TransInt16(content, 23));
+ liftProtocol.setCompleteTaskNo(siemensS7Net.getByteTransform().TransInt16(result1.Content, 6));
//褰撳墠妤煎眰
- liftProtocol.setLev(siemensS7Net.getByteTransform().TransInt16(content, 25));
-
- ///璇诲彇鎻愬崌鏈虹姸鎬�-end
+ liftProtocol.setLev(siemensS7Net.getByteTransform().TransInt16(result1.Content, 8));
//灏嗘彁鍗囨満鐘舵�佷繚瀛樿嚦鏁版嵁搴�
BasLiftService liftService = SpringUtils.getBean(BasLiftService.class);
@@ -205,7 +206,6 @@
basLift.setHasTray(liftProtocol.getHasTray());
basLift.setHasCar(liftProtocol.getHasCar());
basLift.setDeviceError(liftProtocol.getDeviceError());
- basLift.setTaskAddress(liftProtocol.getTaskAddress().intValue());
basLift.setDistAddress(liftProtocol.getDistAddress().intValue());
basLift.setCompleteTaskNo(liftProtocol.getCompleteTaskNo().intValue());
basLift.setLev(liftProtocol.getLev().intValue());
@@ -213,11 +213,52 @@
OutputQueue.LIFT.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
// log.info(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
}
-
}else {
OutputQueue.LIFT.offer(MessageFormat.format("銆恵0}銆憑1}鎻愬崌鏈簆lc鐘舵�佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
throw new CoolException(MessageFormat.format( "鎻愬崌鏈簆lc鐘舵�佷俊鎭け璐� ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort()));
}
+ Thread.sleep(200);
+
+ //鑾峰彇鎻愬崌鏈虹珯鐐规暟鎹�
+ OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB14.0", (short) (10 * liftStaProtocols.size()));
+ if (result1.IsSuccess) {
+ for (int i = 0; i < slave.getSta().size(); i++) {
+ LiftStaProtocol liftStaProtocol = liftStaProtocols.get(i);
+ int i1 = 0 + (i * 10);
+ int i2 = 1 + (i * 10);
+ //璇诲彇x4.0-x4.7鏁版嵁
+ boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result2.Content, i1, 1);
+ //璇诲彇x5.0-x5.7鏁版嵁
+ boolean[] status2 = siemensS7Net.getByteTransform().TransBool(result2.Content, i2, 1);
+ //妯″紡
+ liftStaProtocol.setModel(status1[0]);
+ //蹇欓棽
+ liftStaProtocol.setBusy(status1[1]);
+ //鏈夋墭鐩�
+ liftStaProtocol.setHasTray(status1[2]);
+ //鍓嶈秴闄�
+ liftStaProtocol.setFrontOverrun(status1[4]);
+ //鍚庤秴闄�
+ liftStaProtocol.setBackOverrun(status1[5]);
+ //宸﹁秴闄�
+ liftStaProtocol.setLeftOverrun(status1[6]);
+ //鍙宠秴闄�
+ liftStaProtocol.setRightOverrun(status1[7]);
+ //瓒呴珮
+ liftStaProtocol.setOverHeight(status2[0]);
+ //瓒呴噸
+ liftStaProtocol.setOverWeight(status2[1]);
+ //鏈夊皬杞�
+ liftStaProtocol.setHasCar(status2[6]);
+ //璁惧鏁呴殰
+ liftStaProtocol.setDeviceError(status2[7]);
+ //浠诲姟鍙�
+ liftStaProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt16(result2.Content, 2));
+ //宸插畬鎴愪换鍔″彿
+ liftStaProtocol.setCompleteTaskNo(siemensS7Net.getByteTransform().TransInt16(result2.Content, 6));
+ }
+ }
+
} catch (Exception e) {
OutputQueue.LIFT.offer(MessageFormat.format("銆恵0}銆戞彁鍗囨満plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
}
--
Gitblit v1.9.1