From fbf0dd44dfc4e64b430d4363ed01c06741577a43 Mon Sep 17 00:00:00 2001 From: LSH Date: 星期六, 03 六月 2023 13:47:20 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/SiemensDevpThread.java | 78 +++++++++++++++++++++++++-------------- 1 files changed, 50 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java index c650393..96b194f 100644 --- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java +++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java @@ -11,6 +11,7 @@ import com.core.exception.CoolException; import com.zy.asrs.entity.BasDevp; import com.zy.asrs.service.BasDevpService; +import com.zy.common.utils.News; import com.zy.core.DevpThread; import com.zy.core.cache.MessageQueue; import com.zy.core.cache.OutputQueue; @@ -48,27 +49,16 @@ public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{ add(100);add(101);add(102);add(103); add(104);add(105);add(106);add(107); - add(108);add(109);add(110);add(111); - add(112);add(113);add(114);add(115); - add(116);add(117);add(118);add(119); - add(120);add(121);add(122);add(123); - add(124);add(125);add(126);add(127); - add(128);add(129);add(130);add(131); - add(132);add(133);add(134);add(135); - add(136);add(137);add(138);add(139); - add(140);add(141);add(142);add(143); - add(144);add(145);add(146);add(147); - add(148);add(149);add(150);add(151); - add(152);add(153);add(154);add(155); - add(156);add(157);add(158); }}; public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{ add(200);add(201);add(202);add(203); add(204);add(205);add(206);add(207); - add(208);add(209);add(210);add(211); - add(212);add(213);add(214);add(215); - add(216);add(217); + }}; + + public static final ArrayList<Integer> staNos3 = new ArrayList<Integer>() {{ + add(300);add(301);add(302);add(303); + add(304);add(305);add(306);add(307); }}; @@ -102,6 +92,8 @@ return staNos1; case 2: return staNos2; + case 3: + return staNos3; default: throw new CoolException("鏈嶅姟鍣ㄥ紓甯�"); } @@ -180,10 +172,10 @@ if(connect.IsSuccess){ result = true; OutputQueue.DEVP.offer(MessageFormat.format( "銆恵0}銆戣緭閫佺嚎plc杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); - log.info("杈撻�佺嚎plc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + News.info("SiemensDevp"+" - 1"+" - 杈撻�佺嚎plc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); } else { OutputQueue.DEVP.offer(MessageFormat.format( "銆恵0}銆戣緭閫佺嚎plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); - log.error("杈撻�佺嚎plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + News.error("SiemensDevp"+" - 2"+" - 杈撻�佺嚎plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); } siemensS7Net.ConnectClose(); initSite(); @@ -308,7 +300,7 @@ // if(barcodeThread!=null){ // //lfd鍏ュ簱鍗拌 褰搒tamp>=2鏃舵墠鍏ュ簱 // staProtocol.setStamp(staProtocol.getStamp()+1); -// log.info("{}绔欐湁鍙叆淇″彿鏃讹紝鏉$爜鍊间负{}", siteId, barcodeThread.getBarcode()); +// News.info("{}绔欐湁鍙叆淇″彿鏃讹紝鏉$爜鍊间负{}", siteId, barcodeThread.getBarcode()); // if(Cools.isEmpty(barcodeThread.getBarcode())){ // staProtocol.setInEnable(false);//鏉$爜鏁版嵁涓虹┖鏃讹紝鍏堟竻涓�娆″唴瀛樼殑绔欑偣鍙叆淇″彿锛岀瓑寰呬笅涓�娆¤幏鍙栧彲鍏ヤ俊鍙� // } @@ -353,7 +345,7 @@ initSite(); e.printStackTrace(); OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戞洿鏂版暟鎹簱鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); - log.error("鏇存柊鏁版嵁搴撴暟鎹け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); + News.error("SiemensDevp"+" - 3"+" - 鏇存柊鏁版嵁搴撴暟鎹け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); } } else { @@ -376,20 +368,50 @@ array[1] = staProtocol.getStaNo(); // OperateResult write = siemensS7Net.Write("DB100." + index*4, array); - OperateResult write = siemensS7Net.Write("DB100." + index*2, staProtocol.getWorkNo()); // 宸ヤ綔鍙� - Thread.sleep(500); - OperateResult write1 = siemensS7Net.Write("DB101." + index*2, staProtocol.getStaNo()); // 鐩爣绔� + OperateResult write = null; + OperateResult write1 = null; + //浠诲姟涓嬪彂娆℃暟 + int writeCount = 0; + do { + write = siemensS7Net.Write("DB100." + index*2, staProtocol.getWorkNo()); // 宸ヤ綔鍙� + Thread.sleep(500); + write1 = siemensS7Net.Write("DB101." + index*2, staProtocol.getStaNo()); // 鐩爣绔� + if(write.IsSuccess || write1.IsSuccess){ + Thread.sleep(200); + OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB100." + index*2, (short) 2); + OperateResultExOne<byte[]> readResult1 = siemensS7Net.Read("DB101." + index*2, (short) 2); + if(readResult.IsSuccess && readResult1.IsSuccess){ + short workNo = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 0); + short staNo = siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 0); + if(staProtocol.getWorkNo().equals(workNo) && staProtocol.getStaNo().equals(staNo)){ + //浠诲姟鍛戒护鍐欏叆鎴愬姛 + log.info("鍐欏叆鍫嗗灈鏈哄懡浠ゅ悗杩斿洖鎴愬姛锛屽苟涓斿洖璇绘垚鍔熴�傚爢鍨涙満plc缂栧彿={}锛寋}锛屽啓鍏ユ鏁�={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); + break; + } else {//杩斿洖缁撴灉鏄垚鍔熶簡锛屼絾鏄湡瀹炲�间笉鐩稿悓 + writeCount++; + log.error("鍐欏叆鍫嗗灈鏈哄懡浠ゅ悗杩斿洖鎴愬姛锛屼絾鏄鍙栦换鍔″�间笉涓�鑷淬�傚爢鍨涙満plc缂栧彿={}锛寋}锛屽啓鍏ユ鏁�={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); + } + } else { + writeCount++; + log.error("鍐欏叆鍫嗗灈鏈哄懡浠ゅ悗璇诲彇澶辫触銆傚爢鍨涙満plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); + } + } + else { + writeCount++; + log.error("鍐欏叆鍫嗗灈鏈哄懡浠ゅ悗璇诲彇澶辫触銆傚爢鍨涙満plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); + } + }while (writeCount<5); - if (!write.IsSuccess) { + 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)); + News.error("SiemensDevp"+" - 4"+" - 鍐欏叆杈撻�佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎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)); + News.info("SiemensDevp"+" - 5"+" - 杈撻�佺嚎鍛戒护涓嬪彂 [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}", slave.getId(), JSON.toJSON(staProtocol)); } } @@ -398,7 +420,7 @@ if (this.ioModeOf2F != IoModeType.NONE) { if (!siemensS7Net.Write("DB100.180", this.ioModeOf2F.id).IsSuccess) { OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎2F鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={1}", slave.getId())); - log.error("鍐欏叆杈撻�佺嚎2F鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={}", slave.getId()); + News.error("SiemensDevp"+" - 6"+" - 鍐欏叆杈撻�佺嚎2F鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={}", slave.getId()); } } } @@ -414,7 +436,7 @@ } OperateResult write = siemensS7Net.Write("DB100.50", heartBeatVal); if (!write.IsSuccess) { - log.error("杈撻�佺嚎plc缂栧彿={} 蹇冭烦澶辫触", slave.getId()); + News.error("SiemensDevp"+" - 7"+" - 杈撻�佺嚎plc缂栧彿={} 蹇冭烦澶辫触", slave.getId()); } } -- Gitblit v1.9.1