From 574a90c2d6550fa67dde1994d533fcd4c2a08735 Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期二, 21 十一月 2023 16:02:22 +0800 Subject: [PATCH] #出库过滤同库位组 --- src/main/java/com/zy/core/thread/SiemensDevpThread.java | 148 ++++++++++++------------------------------------- 1 files changed, 36 insertions(+), 112 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..916e57b 100644 --- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java +++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java @@ -41,7 +41,7 @@ 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); @@ -67,6 +67,17 @@ add(346); }}; + //鍑哄叆搴撴ā寮� + public static final ArrayList<Integer> outInModelStaNos = new ArrayList<Integer>() {{ + add(100);add(103); + add(105);add(200); + add(203);add(205); + add(341);add(346); + }}; + + public boolean charge0; + public boolean charge1; + public SiemensDevpThread(DevpSlave slave) { this.slave = slave; } @@ -90,11 +101,6 @@ // 鍐欐暟鎹� ID+鐩爣绔� case 2: write((StaProtocol) task.getData()); - read(); - break; - // 鍑哄叆搴撴ā寮� - case 3: - write3((StaProtocol) task.getData()); read(); break; default: @@ -171,10 +177,21 @@ //璇绘潯鐮� Thread.sleep(100); - OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB1000.200", (short) 88); + OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB1000.200", (short) 98); if (result2.IsSuccess) { for (int i = 0; i < barcodeSize; i++) { - String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8"); + if (i >= 10) { + continue; + } + + String barcode = null; + if (i == 8) { + barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,13, "UTF-8"); + } else if (i == 9) { + barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8 + 6,13, "UTF-8"); + } else { + 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); @@ -190,6 +207,17 @@ Integer siteId = locType1StaNos.get(i); // 绔欑偣缂栧彿 StaProtocol staProtocol = station.get(siteId); staProtocol.setLocType1(siemensS7Net.getByteTransform().TransInt16(result3.Content, i * 2));//璇诲彇楂樹綆淇″彿 + } + } + + //璇诲嚭鍏ュ簱妯″紡 + Thread.sleep(100); + OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB1002.0", (short) (outInModelStaNos.size()*2)); + if (result4.IsSuccess) { + for (int i = 0; i < outInModelStaNos.size(); i++) { + Integer siteId = outInModelStaNos.get(i); // 绔欑偣缂栧彿 + StaProtocol staProtocol = station.get(siteId); + staProtocol.setOutInModel(siemensS7Net.getByteTransform().TransInt16(result4.Content, i * 2));//璇诲彇鍑哄叆搴撴ā寮� } } @@ -216,110 +244,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); - } - } - } /** -- Gitblit v1.9.1