From d314d0c919d13ad27bce4b135fa65c2e18fb2334 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期四, 19 十一月 2020 15:23:07 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/DevpThread.java | 40 ++++++++++++++++++++++++++++++++++++---- 1 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/zy/core/thread/DevpThread.java b/src/main/java/com/zy/core/thread/DevpThread.java index 7382103..90d5837 100644 --- a/src/main/java/com/zy/core/thread/DevpThread.java +++ b/src/main/java/com/zy/core/thread/DevpThread.java @@ -107,7 +107,7 @@ /** * 璇诲彇鐘舵�� ====> 鏁村潡plc */ - private void read(){ + private void read() throws InterruptedException { OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) 40); if (result.IsSuccess) { for (int i = 1; i <= 8; i++) { @@ -121,6 +121,7 @@ staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, (i-1)*2+20)); // 鐩爣绔� } } + Thread.sleep(100); OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB100.40", (short) 8); if (result1.IsSuccess) { for (int i = 1; i <= 8; i++) { @@ -131,9 +132,24 @@ staProtocol.setInEnable(status[2]); // 鍙叆 staProtocol.setOutEnable(status[3]);// 鍙嚭 staProtocol.setEmptyMk(status[4]); // 绌烘澘淇″彿 + + if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { + staProtocol.setPakMk(true); + } } } + // 鍙拌溅浣嶇疆 + OperateResultExOne<Short> result2 = siemensS7Net.ReadInt16("DB100.48"); + if (result2.IsSuccess) { + StaProtocol staProtocol = station.get(8); + staProtocol.setPosition(result2.Content); + } else { + OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆�8鍙峰彴杞﹁幏鍙栧疄鏃朵綅缃け璐ワ紒锛侊紒", DateUtils.convert(new Date()))); + log.error("8鍙峰彴杞﹁幏鍙栧疄鏃朵綅缃け璐ワ紒锛侊紒"); + } + if (result.IsSuccess && result1.IsSuccess) { + OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId())); // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴� @@ -161,11 +177,12 @@ /** * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏� */ - private void write(StaProtocol staProtocol){ + private void write(StaProtocol staProtocol) throws InterruptedException { if (null == staProtocol) { return; } OperateResult write = siemensS7Net.Write("DB100." + (staProtocol.getSiteId() - 1) * 2, staProtocol.getWorkNo()); // 宸ヤ綔鍙� + Thread.sleep(300); OperateResult write1 = siemensS7Net.Write("DB100." + ((staProtocol.getSiteId() - 1) * 2 + 20), staProtocol.getStaNo()); // 鐩爣绔� // boolean[] status = new boolean[8]; // status[0] = staProtocol.isAutoing(); @@ -175,10 +192,15 @@ // status[4] = staProtocol.isEmptyMk(); // OperateResult write2 = siemensS7Net.Write("DB100." + ((staProtocol.getSiteId() - 1) + 40), status); // 鐘舵�� if (!write.IsSuccess || !write1.IsSuccess) { + staProtocol = station.get(staProtocol.getSiteId()); + if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { + staProtocol.setPakMk(true); + } 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))); + 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)); } } @@ -229,12 +251,22 @@ } } + /** + * 璁剧疆鍏ュ簱鏍囪 + */ + public void setPakMk(Integer siteId, boolean pakMk) { + StaProtocol staProtocol = station.get(siteId); + if (null != staProtocol) { + staProtocol.setPakMk(pakMk); + } + } + @Override public void close() { siemensS7Net.ConnectClose(); } - public static void main(String[] args) { + public static void main(String[] args) throws Exception { DevpSlave slave = new DevpSlave(); slave.setIp("192.168.2.125"); DevpThread devpThread = new DevpThread(slave); -- Gitblit v1.9.1