From ed265ddfb8f08f69af064a9adf65fcbf06289ffe Mon Sep 17 00:00:00 2001 From: Junjie <xjj@123> Date: 星期二, 11 二月 2025 14:07:54 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/SiemensDevpThread.java | 170 +++----------------------------------------------------- 1 files changed, 10 insertions(+), 160 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java index d539373..e3e3703 100644 --- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java +++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java @@ -41,30 +41,11 @@ private SiemensS7Net siemensS7Net; private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>(); private short heartBeatVal = 1; - private int barcodeSize = 9; + private int barcodeSize = 10; + public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{ add(100);add(101); add(102);add(103); - add(104);add(105); - add(200);add(201); - add(202);add(203); - add(204);add(205); - add(300);add(301); - add(340);add(341); - add(345);add(346); - add(303);add(317); - add(325);add(331); - add(333);add(339); - add(309);add(312); - }}; - - //楂樹綆淇″彿绔欑偣 - public static final ArrayList<Integer> locType1StaNos = new ArrayList<Integer>() {{ - add(100);add(103); - add(105);add(200); - add(203);add(205); - add(300);add(341); - add(346); }}; public SiemensDevpThread(DevpSlave slave) { @@ -92,17 +73,12 @@ write((StaProtocol) task.getData()); read(); break; - // 鍑哄叆搴撴ā寮� - case 3: - write3((StaProtocol) task.getData()); - read(); - break; default: break; } // 蹇冭烦 // heartbeat(); - Thread.sleep(400); + Thread.sleep(100); } catch (Exception e) { e.printStackTrace(); } @@ -125,7 +101,7 @@ 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())); News.error("杈撻�佺嚎plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); } - siemensS7Net.ConnectClose(); +// siemensS7Net.ConnectClose(); return result; } @@ -147,6 +123,7 @@ staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*4+2)); // 鐩爣绔� } } + Thread.sleep(200); OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB1001.0", (short) (staNos.size()*2)); if (result1.IsSuccess) { @@ -169,30 +146,6 @@ } } - //璇绘潯鐮� - Thread.sleep(100); - OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB1000.200", (short) 88); - if (result2.IsSuccess) { - for (int i = 0; i < barcodeSize; i++) { - String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8"); - BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1); - if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { - barcodeThread.setBarcode(barcode); - } - } - } - - //璇婚珮浣庝俊鍙� - Thread.sleep(100); - OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB1000.300", (short) (locType1StaNos.size()*2)); - if (result3.IsSuccess) { - for (int i = 0; i < locType1StaNos.size(); i++) { - Integer siteId = locType1StaNos.get(i); // 绔欑偣缂栧彿 - StaProtocol staProtocol = station.get(siteId); - staProtocol.setLocType1(siemensS7Net.getByteTransform().TransInt16(result3.Content, i * 2));//璇诲彇楂樹綆淇″彿 - } - } - if (result.IsSuccess && result1.IsSuccess) { OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId())); @@ -202,6 +155,7 @@ for (Integer siteId : staNos) { StaProtocol staProtocol = station.get(siteId); basDevps.add(staProtocol.toSqlModel()); +// log.info("杈撻�佺嚎淇″彿锛寋}", JSON.toJSONString(staProtocol)); } BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); if (!basDevpService.updateBatchById(basDevps)) { @@ -216,110 +170,6 @@ 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())); // News.error("璇诲彇杈撻�佺嚎plc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); } - } - - /** - * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏� - */ - private void write3(StaProtocol staProtocol) throws InterruptedException { - if (Cools.isEmpty(staProtocol)) { - return; - } - OperateResult writeResult = null; - //浠诲姟涓嬪彂娆℃暟 - int writeCount = 0; - //浠诲姟涓嬪彂鎴愬姛鏍囪瘑 - boolean writeFlag = false; - - Short outAndIn = staProtocol.getOutInModel(); - Integer siteId = staProtocol.getSiteId(); - Short run = 0;//鍋滄杞姩 - String address = ""; - if (staProtocol.getRotationDire() != null) { - run = staProtocol.getRotationDire().shortValue();//杞姩鏂瑰悜 - } - switch (siteId) { - case 102: - address = "DB100.300"; - break; - case 105: - address = "DB100.302"; - break; - case 106: - address = "DB100.304"; - break; - case 107: - address = "DB100.306"; - break; - case 108: - address = "DB100.308"; - break; - } - - while(writeCount < 5){ - writeResult = siemensS7Net.Write(address, run); - if (writeResult == null) { - log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); - continue; - } - - if(writeResult.IsSuccess){ - Thread.sleep(200); - OperateResultExOne<byte[]> readResult = siemensS7Net.Read(address, (short) 2); - if(readResult.IsSuccess){ - short run2 = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 0); - if(run.equals(run2)){ - //浠诲姟鍛戒护鍐欏叆鎴愬姛 - writeFlag = true; - if (staProtocol.getStaNo() != null && staProtocol.getWorkNo() != null) { - write(staProtocol);//鍐欏叆宸ヤ綔鍙峰拰鐩爣绔� - } - log.info("鍐欏叆杈撻�佺嚎鍛戒护鍚庤繑鍥炴垚鍔燂紝骞朵笖鍥炶鎴愬姛銆傝緭閫佺嚎plc缂栧彿={}锛寋}锛屽啓鍏ユ鏁�={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); - break; - } else {//杩斿洖缁撴灉鏄垚鍔熶簡锛屼絾鏄湡瀹炲�间笉鐩稿悓 - writeCount++; - OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护鍚庤繑鍥炴垚鍔燂紝浣嗘槸璇诲彇浠诲姟鍊间笉涓�鑷淬�傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2},鍐欏叆娆℃暟={3}", - slave.getId(), JSON.toJSON(staProtocol),writeCount)); - log.error("鍐欏叆杈撻�佺嚎鍛戒护鍚庤繑鍥炴垚鍔燂紝浣嗘槸璇诲彇浠诲姟鍊间笉涓�鑷淬�傝緭閫佺嚎plc缂栧彿={}锛寋}锛屽啓鍏ユ鏁�={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); - } - } else { - writeCount++; - OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护鍚庤鍙栧け璐ャ�傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2},鍐欏叆娆℃暟={3}", - slave.getId(), JSON.toJSON(staProtocol), writeCount)); - log.error("鍐欏叆杈撻�佺嚎鍛戒护鍚庤鍙栧け璐ャ�傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); - } - } else { - writeCount++; - OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2},鍐欏叆娆℃暟={3}", - slave.getId(), JSON.toJSON(staProtocol),writeCount)); - log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); - } - Thread.sleep(200); - } - - //鍐欏懡浠ゅ皾璇曚簡5娆¤繕鏄け璐ヤ簡 - if(!writeFlag){ - staProtocol = station.get(staProtocol.getSiteId()); - if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { - staProtocol.setPakMk(true); - } - OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护灏濊瘯5娆″け璐ャ�傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2}", slave.getId(), JSON.toJSON(staProtocol))); - log.error("鍐欏叆杈撻�佺嚎鍛戒护灏濊瘯5娆″け璐ャ�傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={}", slave.getId(), JSON.toJSON(staProtocol)); - - //閲嶆柊娣诲姞鏁版嵁鍒颁换鍔¢槦鍒� - boolean result = MessageQueue.offer(SlaveType.Devp, slave.getId(), new Task(3, staProtocol)); - read();//璇诲彇1娆¤澶囩姸鎬� - return; - } 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)); - - staProtocol = station.get(siteId); - if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { - staProtocol.setPakMk(true); - } - } - } /** @@ -342,10 +192,10 @@ int writeCount = 0; //浠诲姟涓嬪彂鎴愬姛鏍囪瘑 boolean writeFlag = false; - while(writeCount < 5){ + while(writeCount < 1){ writeResult = siemensS7Net.Write("DB1000." + index*4, array); // 宸ヤ綔鍙枫�佺洰鏍囩珯 if(writeResult.IsSuccess){ - Thread.sleep(200); + Thread.sleep(500); OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB1000." + index*4, (short)4); if(readResult.IsSuccess){ short workNo = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 0); @@ -385,8 +235,8 @@ OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护灏濊瘯5娆″け璐ャ�傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2}", slave.getId(), JSON.toJSON(staProtocol))); log.error("鍐欏叆杈撻�佺嚎鍛戒护灏濊瘯5娆″け璐ャ�傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={}", slave.getId(), JSON.toJSON(staProtocol)); - //閲嶆柊娣诲姞鏁版嵁鍒颁换鍔¢槦鍒� - boolean result = MessageQueue.offer(SlaveType.Devp, slave.getId(), new Task(2, staProtocol)); +// //閲嶆柊娣诲姞鏁版嵁鍒颁换鍔¢槦鍒� +// boolean result = MessageQueue.offer(SlaveType.Devp, slave.getId(), new Task(2, staProtocol)); read();//璇诲彇1娆¤澶囩姸鎬� return; } else { -- Gitblit v1.9.1