From c5c1d3745bed9021ce4f90dcaa15c5b25cf4c05c Mon Sep 17 00:00:00 2001 From: zjj <3272660260@qq.com> Date: 星期五, 19 一月 2024 21:31:42 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/SiemensDevpThread.java | 67 ++++++++++++++++----------------- 1 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java index a7ba3b2..edb31c2 100644 --- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java +++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java @@ -66,6 +66,12 @@ add(200);add(201);add(202); }}; + public static final ArrayList<Integer> BarcodeList = new ArrayList<Integer>() {{ + add(0); add(1); add(2); + }}; + public static final ArrayList<Integer> staNosErrList = new ArrayList<Integer>() {{ + add(106); add(107); add(159); + }}; private Integer count=0; @@ -267,16 +273,34 @@ // } //鏉$爜鎵弿鍣� - Thread.sleep(200); - OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.0",(short)(barcodeSize*8)); + ArrayList<Integer> barcodeList = BarcodeList; + OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.840", (short) (barcodeList.size() * 8)); if (result2.IsSuccess) { - for (int i = 0; i < barcodeSize; i++) { + for (int i = 0; i < barcodeList.size(); i++) { + Integer barcodeId = barcodeList.get(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)){ -// && !Cools.isEmpty(barcode) && Cools.isEmpty(barcodeThread.getBarcode())) { + BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1); + if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { barcodeThread.setBarcode(barcode); } + } + } + //澶栧舰妫�娴� + ArrayList<Integer> staNoErrs = staNosErrList; + int staNoErrsSize = staNoErrs.size(); + OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.800", (short) (staNoErrsSize*8)); + if (resultErr.IsSuccess){ + for (int i = 0;i<3;i++){ + Integer siteId = staNoErrs.get(i); // 绔欑偣缂栧彿 + boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*4+2, 1); + StaProtocol staProtocol = station.get(siteId); + staProtocol.setFrontErr(status[0]); + staProtocol.setBackErr(status[1]); + staProtocol.setHighErr(status[2]); + staProtocol.setLeftErr(status[3]); + staProtocol.setRightErr(status[4]); + staProtocol.setWeightErr(status[5]); + staProtocol.setBarcodeErr(status[6]); } } @@ -318,45 +342,20 @@ } ArrayList<Integer> staNos = getStaNo(); int index = staNos.indexOf(staProtocol.getSiteId()); -// short[] array = new short[2]; -// array[0] = staProtocol.getWorkNo(); -// array[1] = staProtocol.getStaNo(); -// OperateResult write = siemensS7Net.Write("DB100." + index*4, array); - OperateResult write = null; OperateResult write1 = null; //浠诲姟涓嬪彂娆℃暟 int writeCount = 0; do { -// write = siemensS7Net.Write("DB100.0" + index*2, staProtocol.getWorkNo()); // 宸ヤ綔鍙� -// Thread.sleep(500); -// write1 = siemensS7Net.Write("DB100.0" + index*2+2, staProtocol.getStaNo()); // 鐩爣绔� write = siemensS7Net.Write("DB100." + index*6, staProtocol.getWorkNo()); // 宸ヤ綔鍙� - Thread.sleep(500); + Thread.sleep(200); write1 = siemensS7Net.Write("DB100." + (index*6+4), staProtocol.getStaNo().shortValue()); // 鐩爣绔� if(write.IsSuccess && write1.IsSuccess){ - Thread.sleep(200); - OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB100.0" + index*2, (short) 2); - OperateResultExOne<byte[]> readResult1 = siemensS7Net.Read("DB100.0" + index*2+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); - } + break; } else { writeCount++; - log.error("鍐欏叆鍫嗗灈鏈哄懡浠ゅ悗璇诲彇澶辫触銆傚爢鍨涙満plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); + log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); } }while (writeCount<5); -- Gitblit v1.9.1