From 2c07ded302650568c80a1fe1bc6a9522b978bd36 Mon Sep 17 00:00:00 2001 From: lty <876263681@qq.com> Date: 星期六, 19 七月 2025 09:20:02 +0800 Subject: [PATCH] #调度 --- src/main/java/com/zy/core/thread/SiemensDevpThread.java | 128 ++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 120 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java index 2bf4d3a..a36c7b6 100644 --- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java +++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java @@ -77,13 +77,32 @@ add(10); add(11); add(12); add(13); }}; public static final ArrayList<Integer> staNosErrList2 = new ArrayList<Integer>() {{ - add(101); add(104);add(106);add(108); - add(202);add(204);add(207);add(210); + add(102); add(105);add(107);add(109); + add(203);add(205);add(208);add(211); }}; public static final ArrayList<Integer> staNosErrList1 = new ArrayList<Integer>() {{ + add(123); + add(223);add(225);add(228);add(231); + }}; + + public static final ArrayList<Integer> staNoWeight1 = new ArrayList<Integer>() {{ + add(223);add(225);add(228);add(231); + }}; + + public static final ArrayList<Integer> staNoWeight2 = new ArrayList<Integer>() {{ + add(102);add(105);add(107);add(109); + add(203);add(205);add(208);add(211); + }}; + + public static final ArrayList<Integer> staNosInList1 = new ArrayList<Integer>() {{ add(122); add(222);add(224);add(227);add(230); + }}; + + public static final ArrayList<Integer> staNosInList2 = new ArrayList<Integer>() {{ + add(101); add(104);add(106);add(108); + add(202);add(204);add(207);add(210); }}; private Integer count=0; @@ -110,12 +129,34 @@ this.slave = slave; } + private ArrayList<Integer> getStaNoIn() { + switch (slave.getId()) { + case 1: + return staNosInList1; + case 2: + return staNosInList2; + default: + throw new CoolException("鏈嶅姟鍣ㄥ紓甯�"); + } + } + private ArrayList<Integer> getStaNoErr() { switch (slave.getId()) { case 1: return staNosErrList1; case 2: return staNosErrList2; + default: + throw new CoolException("鏈嶅姟鍣ㄥ紓甯�"); + } + } + + private ArrayList<Integer> getStaNoWeight() { + switch (slave.getId()) { + case 1: + return staNoWeight1; + case 2: + return staNoWeight2; default: throw new CoolException("鏈嶅姟鍣ㄥ紓甯�"); } @@ -162,6 +203,9 @@ case 2: write((StaProtocol)task.getData()); log.error("杈撻�佺嚎涓嬪彂鍛戒护锛�"+((StaProtocol) task.getData()).getWorkNo()+","+((StaProtocol) task.getData()).getStaNo()); + break; + case 3: + write2((StaProtocol)task.getData()); break; default: break; @@ -221,7 +265,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("SiemensDevp"+" - 2"+" - 杈撻�佺嚎plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); } - siemensS7Net.ConnectClose(); +// siemensS7Net.ConnectClose(); initSite(); return result; } @@ -246,12 +290,24 @@ private void read() throws InterruptedException { // // 鏇存柊鍏ュ嚭搴撴ā寮� // updateIoMode(); + +// if (slave.getId()==1) return; ArrayList<Integer> staNos = getStaNo(); ArrayList<Integer> staNosErrList = getStaNoErr(); + ArrayList<Integer> staNoWeight = getStaNoWeight(); + ArrayList<Integer> staNosInList = getStaNoIn(); int staNoSize = staNos.size(); OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (500 * 8)); + OperateResultExOne<byte[]> resultWeight = null; + if(staNoWeight.size()>4){ + resultWeight = siemensS7Net.Read("DB102.0", (short) (8 * 4)); + }else{ + resultWeight = siemensS7Net.Read("DB102.0", (short) (4 * 4)); + } + OperateResultExOne<byte[]> resultWeight2 = siemensS7Net.Read("DB102.0", (short) (4 * 4)); - if (result.IsSuccess) { + if (result.IsSuccess && resultWeight.IsSuccess) { + int j = 0; for(int i = 0 ; i<staNoSize;i++){ Integer siteId = staNos.get(i); // 绔欑偣缂栧彿 StaProtocol staProtocol = station.get(siteId); @@ -264,9 +320,17 @@ int offset = getOffsetFromSiteId(siteId);//鍙栦綑鑾峰緱瀵瑰簲db鍧楁暟鎹� staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result.Content, offset)); // 宸ヤ綔鍙� + if (staNoWeight.contains(siteId)) { + if(staNoWeight.size() == 4){ + staProtocol.setWeight(siemensS7Net.getByteTransform().TransInt32(resultWeight2.Content, j)); + j = j + 4; + }else{ + staProtocol.setWeight(siemensS7Net.getByteTransform().TransInt32(resultWeight.Content, j)); + j = j + 4; + } + } staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, offset+ 4)); // 鐩爣绔� - status = siemensS7Net.getByteTransform().TransBool(result.Content, offset+ 6, 2); staProtocol.setAutoing(status[0]); // 鑷姩 @@ -315,6 +379,20 @@ staProtocol.setBarcodeErr(status[6]); } } + + //鍏ュ簱婊¤冻 + ArrayList<Integer> staNosIns = staNosInList; + int staNosInSize = staNosIns.size(); + OperateResultExOne<byte[]> resultIn = siemensS7Net.Read("DB1000.0", (short) (staNosInSize * 6)); + if(resultIn.IsSuccess){ + for (int i = 0; i < staNosInSize; i++) { + Integer siteId = staNosIns.get(i); + StaProtocol staProtocol = station.get(siteId); + staProtocol.setStamp( siemensS7Net.getByteTransform().TransInt16(resultIn.Content, i*6)); + } + } + + // //plc鏁呴殰 // OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB101.1728", (short) (staNoSize*4)); @@ -393,9 +471,43 @@ } - /** - * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏� - */ + + private void write2(StaProtocol staProtocol) throws InterruptedException { + OperateResult write = null; + int writeCount = 0; + ArrayList<Integer> staNosInList = getStaNoIn(); + + ArrayList<Integer> staNosIns = staNosInList; + int staNosInSize = staNosIns.size(); + OperateResultExOne<byte[]> resultIn = siemensS7Net.Read("DB1000.0", (short) (staNosInSize * 6)); + int offset = 0; + if(resultIn.IsSuccess){ + for (int i = 0; i < staNosInSize; i++) { + Integer siteId = staNosIns.get(i); + if(staProtocol.getSiteId().equals(siteId)){ + offset = i*6 + 2; + break; + } + } + } + do { + write = siemensS7Net.Write("DB1000.0" + offset,staProtocol.getWorkNo()); // 宸ヤ綔鍙� + + if(write.IsSuccess ){ + log.error("宸ヤ綔鍙穥}",staProtocol.getWorkNo()); + log.error("鍐欏叆杈撻�佺嚎鍛戒护鎴愬姛銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); + break; + } + else { + writeCount++; + log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); + } + }while (writeCount<5); + } + + /** + * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏� + */ private void write(StaProtocol staProtocol) throws InterruptedException { if (null == staProtocol) { return; -- Gitblit v1.9.1