From 2a35d8deefb89c4b463fdbafe79f2c7bd294621d Mon Sep 17 00:00:00 2001 From: zjj <3272660260@qq.com> Date: 星期四, 23 五月 2024 12:56:13 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/SiemensDevpThread.java | 252 ++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 224 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 6c52775..3f59baa 100644 --- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java +++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java @@ -47,6 +47,7 @@ private SiemensS7Net siemensS7Net; private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>(); private short heartBeatVal = 1; + private Integer rgvCount = 4; 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); @@ -124,6 +125,11 @@ // 鍐欐暟鎹� ID+鐩爣绔� case 2: write((StaProtocol)task.getData()); + read(); + break; + case 3: + write2((StaProtocol)task.getData()); + read(); break; default: break; @@ -161,6 +167,19 @@ if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { staProtocol.setPakMk(true); + } + } + if (slave.getId() == 2){ + for (int i = 1;i<5;i++){ + StaProtocol staProtocol = station.get(i); + if (null == staProtocol) { + staProtocol = new StaProtocol(); + staProtocol.setSiteId(i); + station.put(i, staProtocol); + } + staProtocol.setWorkNo((short) 0); + staProtocol.setNearbySta((short) 3); + staProtocol.setLoading(false); } } } @@ -211,7 +230,7 @@ } } - Thread.sleep(200); + //Thread.sleep(200); OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB101.0", (short) (staNoSize*2)); if (result1.IsSuccess) { for (int i = 0; i < staNoSize; i++) { @@ -233,10 +252,33 @@ } } + if (slave.getId() == 2){ + + OperateResultExOne<byte[]> resultRgvWrkNo = siemensS7Net.Read("DB55.222", (short) 98); + OperateResultExOne<byte[]> resultRgvLocation = siemensS7Net.Read("DB43.0", (short) 8); + OperateResultExOne<byte[]> resultRgvload = siemensS7Net.Read("DB192.0", (short) 8); + if (resultRgvWrkNo.IsSuccess && resultRgvLocation.IsSuccess && resultRgvload.IsSuccess){ + for (int i = 1;i<5;i++){ + short wrkNo = siemensS7Net.getByteTransform().TransInt16(resultRgvWrkNo.Content, i * 32); + short location = siemensS7Net.getByteTransform().TransInt16(resultRgvLocation.Content, i * 2); + boolean[] status = siemensS7Net.getByteTransform().TransBool(resultRgvload.Content, i*2, 1); + StaProtocol staProtocol = station.get(i); + if (null == staProtocol) { + staProtocol = new StaProtocol(); + staProtocol.setSiteId(i); + station.put(i, staProtocol); + } + staProtocol.setWorkNo(wrkNo); + staProtocol.setNearbySta(location); + staProtocol.setLoading(status[0]); + } + } + } + if (slave.getId() == 1){ //鏉$爜 - Thread.sleep(200); + //Thread.sleep(200); OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.102",(short)60); if (result2.IsSuccess) { for (int i = 0; i < 6; i++) { @@ -249,8 +291,8 @@ } // 澶栧舰妫�娴� - 102 - Thread.sleep(100); - OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB101.150", (short)1); + //Thread.sleep(100); + OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB101.160", (short)1); if (result4.IsSuccess) { boolean[] status = siemensS7Net.getByteTransform().TransBool(result4.Content, 0, 1); StaProtocol staProtocol = station.get(103); @@ -263,8 +305,8 @@ staProtocol.setBarcodeErr(status[6]); } // 澶栧舰妫�娴� - 107 - Thread.sleep(50); - OperateResultExOne<byte[]> result5 = siemensS7Net.Read("DB101.154", (short)1); + //Thread.sleep(50); + OperateResultExOne<byte[]> result5 = siemensS7Net.Read("DB101.164", (short)1); if (result5.IsSuccess) { boolean[] status = siemensS7Net.getByteTransform().TransBool(result5.Content, 0, 1); StaProtocol staProtocol = station.get(107); @@ -277,8 +319,8 @@ staProtocol.setBarcodeErr(status[6]); } // 澶栧舰妫�娴� - 111 - Thread.sleep(50); - OperateResultExOne<byte[]> result6 = siemensS7Net.Read("DB101.158", (short)1); + //Thread.sleep(50); + OperateResultExOne<byte[]> result6 = siemensS7Net.Read("DB101.168", (short)1); if (result6.IsSuccess) { boolean[] status = siemensS7Net.getByteTransform().TransBool(result6.Content, 0, 1); StaProtocol staProtocol = station.get(111); @@ -291,8 +333,8 @@ staProtocol.setBarcodeErr(status[6]); } // 澶栧舰妫�娴� - 115 - Thread.sleep(50); - OperateResultExOne<byte[]> result7 = siemensS7Net.Read("DB101.162", (short)1); + //Thread.sleep(50); + OperateResultExOne<byte[]> result7 = siemensS7Net.Read("DB101.172", (short)1); if (result7.IsSuccess) { boolean[] status = siemensS7Net.getByteTransform().TransBool(result7.Content, 0, 1); StaProtocol staProtocol = station.get(115); @@ -305,8 +347,8 @@ staProtocol.setBarcodeErr(status[6]); } // 澶栧舰妫�娴� - 119 - Thread.sleep(50); - OperateResultExOne<byte[]> result8 = siemensS7Net.Read("DB101.166", (short)1); + //Thread.sleep(50); + OperateResultExOne<byte[]> result8 = siemensS7Net.Read("DB101.176", (short)1); if (result8.IsSuccess) { boolean[] status = siemensS7Net.getByteTransform().TransBool(result8.Content, 0, 1); StaProtocol staProtocol = station.get(119); @@ -319,8 +361,8 @@ staProtocol.setBarcodeErr(status[6]); } // 澶栧舰妫�娴� - 123 - Thread.sleep(50); - OperateResultExOne<byte[]> result9 = siemensS7Net.Read("DB101.170", (short)1); + //Thread.sleep(50); + OperateResultExOne<byte[]> result9 = siemensS7Net.Read("DB101.180", (short)1); if (result9.IsSuccess) { boolean[] status = siemensS7Net.getByteTransform().TransBool(result9.Content, 0, 1); StaProtocol staProtocol = station.get(123); @@ -333,8 +375,16 @@ staProtocol.setBarcodeErr(status[6]); } } else if (slave.getId() == 3) { - // 澶栧舰妫�娴� - 111 - Thread.sleep(50); + //鏉$爜 + //Thread.sleep(200); + OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.18",(short)10); + if (result2.IsSuccess) { + String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,0,8, "UTF-8"); + BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 7); + if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { + barcodeThread.setBarcode(barcode); + } + } OperateResultExOne<byte[]> result10 = siemensS7Net.Read("DB101.26", (short)1); if (result10.IsSuccess) { boolean[] status = siemensS7Net.getByteTransform().TransBool(result10.Content, 0, 1); @@ -347,7 +397,74 @@ staProtocol.setWeightErr(status[5]); staProtocol.setBarcodeErr(status[6]); } + } else if (slave.getId() == 4) { + //鏉$爜 + OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.18",(short)10); + if (result2.IsSuccess) { + + String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,0,8, "UTF-8"); + BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 8); + if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { + barcodeThread.setBarcode(barcode); + } + } + // 澶栧舰妫�娴� - 111 + //Thread.sleep(50); + OperateResultExOne<byte[]> result10 = siemensS7Net.Read("DB101.26", (short)1); + if (result10.IsSuccess) { + boolean[] status = siemensS7Net.getByteTransform().TransBool(result10.Content, 0, 1); + StaProtocol staProtocol = station.get(401); + 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]); + + } } + + if(slave.getId() != 2){ + OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB13.2", (short) (staNoSize*4)); + if (resultErr.IsSuccess) { + for (int i = 0; i < staNoSize; i++) { + Integer siteId = staNos.get(i); // 绔欑偣缂栧彿 + boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*4, 1); + StaProtocol staProtocol = station.get(siteId); + staProtocol.setBreakerErr(status[0]); + staProtocol.setInfraredErr(status[1]); + staProtocol.setOutTimeErr(status[2]); + staProtocol.setSeizeSeatErr(status[3]); + staProtocol.setWrkYgoodsN(status[4]); + staProtocol.setInverterErr(status[5]); + staProtocol.setContactErr(status[6]); + staProtocol.setUpcontactErr(status[7]); + + } + } + }else { + OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB1003.2", (short) (staNoSize*4)); + if (resultErr.IsSuccess) { + for (int i = 0; i < staNoSize; i++) { + Integer siteId = staNos.get(i); // 绔欑偣缂栧彿 + boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*4, 1); + StaProtocol staProtocol = station.get(siteId); + staProtocol.setBreakerErr(status[0]); + staProtocol.setInfraredErr(status[1]); + staProtocol.setOutTimeErr(status[2]); + staProtocol.setSeizeSeatErr(status[3]); + staProtocol.setWrkYgoodsN(status[4]); + staProtocol.setInverterErr(status[5]); + staProtocol.setContactErr(status[6]); + staProtocol.setUpcontactErr(status[7]); + + } + } + } + + + // //RGV鍙拌溅浣嶇疆 @@ -398,6 +515,7 @@ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.deleteDeviceError("devp", slave.getId()); } else { + initSite(); 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:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); @@ -450,9 +568,6 @@ boolean writeFlag = false; while(writeCount < 5){ writeResult = siemensS7Net.Write("DB100." + index*4, array); // 宸ヤ綔鍙枫�佺洰鏍囩珯 - //鏇存柊鎸囦护鏃ュ織 - commandInfoLog.setDeviceLog("鎸囦护涓嬪彂鎴愬姛"); - commandInfoLogService.insert(commandInfoLog); if(writeResult.IsSuccess){ Thread.sleep(200); @@ -465,12 +580,19 @@ writeFlag = true; log.info("鍐欏叆杈撻�佺嚎鍛戒护鍚庤繑鍥炴垚鍔燂紝骞朵笖鍥炶鎴愬姛銆傝緭閫佺嚎plc缂栧彿={}锛寋}锛屽啓鍏ユ鏁�={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); + Date now = new Date(); + //鏇存柊鎸囦护鐘舵�� commandInfo.setCommandStatus(CommandStatusType.COMPLETE.id);//杈撻�佺嚎鐩存帴瀹屾垚鐘舵�� + commandInfo.setExecuteTime(now); + commandInfo.setCompleteTime(now); commandInfoService.updateById(commandInfo); //鏇存柊鎸囦护鏃ュ織 commandInfoLog.setDeviceLog("鎸囦护涓嬪彂鎴愬姛"); + commandInfoLog.setCommandStatus(CommandStatusType.COMPLETE.id);//杈撻�佺嚎鐩存帴瀹屾垚鐘舵�� + commandInfoLog.setExecuteTime(now); + commandInfoLog.setCompleteTime(now); commandInfoLogService.insert(commandInfoLog); //鏇存柊浠诲姟姝ュ簭 @@ -488,7 +610,7 @@ slave.getId(), JSON.toJSON(staProtocol),writeCount)); log.error("鍐欏叆杈撻�佺嚎鍛戒护鍚庤繑鍥炴垚鍔燂紝浣嗘槸璇诲彇浠诲姟鍊间笉涓�鑷淬�傝緭閫佺嚎plc缂栧彿={}锛寋}锛屽啓鍏ユ鏁�={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); //鏇存柊鎸囦护鏃ュ織 - commandInfoLog.setDeviceLog("鎸囦护涓嬪彂鎴愬姛"); + commandInfoLog.setDeviceLog("鎸囦护涓嬪彂澶辫触"); commandInfoLogService.insert(commandInfoLog); } } else { @@ -529,7 +651,88 @@ 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)); + //log.info("杈撻�佺嚎鍛戒护涓嬪彂 [id:{}] >>>>> 鍛戒护涓嬪彂鎴愬姛锛� {}", slave.getId(), JSON.toJSON(staProtocol)); + + Integer siteId = staProtocol.getSiteId(); + staProtocol = station.get(siteId); + if ((siteId == 101 || siteId == 201)&&(staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0)) { + staProtocol.setPakMk(true); + } + } + + } + private void write2(StaProtocol staProtocol) throws InterruptedException { + if (null == staProtocol) { + return; + } + ArrayList<Integer> staNos = getStaNo(); + + int index = staNos.indexOf(staProtocol.getSiteId()); + short[] array = new short[2]; + array[0] = staProtocol.getWorkNo(); + array[1] = staProtocol.getStaNo(); + + OperateResult writeResult; + //浠诲姟涓嬪彂娆℃暟 + int writeCount = 0; + //浠诲姟涓嬪彂鎴愬姛鏍囪瘑 + boolean writeFlag = false; + while(writeCount < 5){ + writeResult = siemensS7Net.Write("DB100." + index*4, array); // 宸ヤ綔鍙枫�佺洰鏍囩珯 + + if(writeResult.IsSuccess){ + Thread.sleep(200); + OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB100." + index*4, (short)4); + if(readResult.IsSuccess){ + short workNo = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 0); + short staNo = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 2); + if(staProtocol.getWorkNo().equals(workNo) && staProtocol.getStaNo().equals(staNo)){ + //浠诲姟鍛戒护鍐欏叆鎴愬姛 + writeFlag = true; + log.info("鍐欏叆杈撻�佺嚎鍛戒护鍚庤繑鍥炴垚鍔燂紝骞朵笖鍥炶鎴愬姛銆傝緭閫佺嚎plc缂栧彿={}锛寋}锛屽啓鍏ユ鏁�={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); + + Date now = new Date(); + 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)); Integer siteId = staProtocol.getSiteId(); staProtocol = station.get(siteId); @@ -537,13 +740,6 @@ staProtocol.setPakMk(true); } - //鏇存柊浠诲姟姝ュ簭 - TaskWrkService taskWrkService = SpringUtils.getBean(TaskWrkService.class); - TaskWrk taskWrk = taskWrkService.selectByWrkNo(staProtocol.getWorkNo().intValue()); - if (taskWrk != null) { - taskWrk.setCommandStep(taskWrk.getCommandStep() + 1);//鏇存柊鎸囦护姝ュ簭 - taskWrkService.updateById(taskWrk); - } } } -- Gitblit v1.9.1