From 9fd40b787bdd4e0caaed213d1931d9c7fb8f846c Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期三, 30 十二月 2020 09:46:33 +0800 Subject: [PATCH] ## --- src/main/java/com/zy/core/thread/MelsecDevpThread.java | 35 ++++++++++++++++++++--------------- 1 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/zy/core/thread/MelsecDevpThread.java b/src/main/java/com/zy/core/thread/MelsecDevpThread.java index ddf5e9a..1cfa839 100644 --- a/src/main/java/com/zy/core/thread/MelsecDevpThread.java +++ b/src/main/java/com/zy/core/thread/MelsecDevpThread.java @@ -72,7 +72,7 @@ } // 蹇冭烦 - heartbeat(); +// heartbeat(); Thread.sleep(400); } catch (Exception e) { e.printStackTrace(); @@ -95,6 +95,9 @@ log.error("杈撻�佺嚎plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); } melsecMcNet.ConnectClose(); + try { + Thread.sleep(1000); + } catch (InterruptedException ignore) {} return result; } @@ -105,7 +108,7 @@ OperateResultExOne<byte[]> result = melsecMcNet.Read("D101", (short) 30); if (result.IsSuccess) { // 绔欑偣鏁版嵁 - for (int i = 1; i <= staNos.size(); i++) { + for (int i = 0; i < staNos.size(); i++) { Integer siteId = staNos.get(i); // 绔欑偣缂栧彿 StaProtocol staProtocol = station.get(siteId); if (null == staProtocol) { @@ -113,20 +116,22 @@ staProtocol.setSiteId(siteId); station.put(siteId, staProtocol); } - staProtocol.setWorkNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2)); // 宸ヤ綔鍙� - staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2+40)); // 鐩爣绔� + short workNo = melsecMcNet.getByteTransform().TransInt16(result.Content, (i) * 2); + staProtocol.setWorkNo(workNo==-1?0:workNo); // 宸ヤ綔鍙� + staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i)*2+40)); // 鐩爣绔� } } - Thread.sleep(3000); + Thread.sleep(200); OperateResultExOne<boolean[]> result1 = melsecMcNet.ReadBool("M800", (short) 64); if (result1.IsSuccess) { - for (int i = 1; i <= 7; i++) { - StaProtocol staProtocol = station.get(i); - staProtocol.setAutoing(result1.Content[(i-1)*8]); // 鑷姩 - staProtocol.setLoading(result1.Content[(i-1)*8+1]); // 鏈夌墿 - staProtocol.setInEnable(result1.Content[(i-1)*8+2]); // 鍙叆 - staProtocol.setOutEnable(result1.Content[(i-1)*8+3]);// 鍙嚭 - staProtocol.setEmptyMk(result1.Content[(i-1)*8+4]); // 绌烘澘淇″彿 + for (int i = 0; i < staNos.size(); i++) { + Integer siteId = staNos.get(i); // 绔欑偣缂栧彿 + StaProtocol staProtocol = station.get(siteId); + staProtocol.setAutoing(result1.Content[(i)*8]); // 鑷姩 + staProtocol.setLoading(result1.Content[(i)*8+1]); // 鏈夌墿 + staProtocol.setInEnable(result1.Content[(i)*8+2]); // 鍙叆 + staProtocol.setOutEnable(result1.Content[(i)*8+3]);// 鍙嚭 + staProtocol.setEmptyMk(result1.Content[(i)*8+4]); // 绌烘澘淇″彿 if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { staProtocol.setPakMk(true); @@ -175,9 +180,10 @@ if (null == staProtocol) { return; } - OperateResult write = melsecMcNet.Write("D1" + Utils.zerofill(String.valueOf(staNos.indexOf(staProtocol.getSiteId())+1), 2), staProtocol.getWorkNo()); // 宸ヤ綔鍙� - Thread.sleep(400); + System.out.println(); OperateResult write1 = melsecMcNet.Write("D1" + Utils.zerofill(String.valueOf(staNos.indexOf(staProtocol.getSiteId())+21), 2), staProtocol.getStaNo()); // 鐩爣绔� + Thread.sleep(200); + OperateResult write = melsecMcNet.Write("D1" + Utils.zerofill(String.valueOf(staNos.indexOf(staProtocol.getSiteId())+1), 2), staProtocol.getWorkNo()); // 宸ヤ綔鍙� if (!write.IsSuccess || !write1.IsSuccess) { staProtocol = station.get(staProtocol.getSiteId()); if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { @@ -186,7 +192,6 @@ OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2}", slave.getId(), JSON.toJSON(staProtocol))); log.error("鍐欏叆杈撻�佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={}", slave.getId(), JSON.toJSON(staProtocol)); } else { - log.error("-------------------------------------------绗笁姝ャ�乕绔欑偣鍙凤細{}][宸ヤ綔鍙凤細{}]==>> 涓嬪彂杈撻�佺嚎鍚姩淇″彿鎴愬姛锛侊紒",staProtocol.getSiteId(),staProtocol.getWorkNo()); 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)); } -- Gitblit v1.9.1