From 69956cd46e68d240701b6269cc0d01862e450c82 Mon Sep 17 00:00:00 2001 From: zhangc <zc@123> Date: 星期一, 24 三月 2025 14:50:07 +0800 Subject: [PATCH] 1 --- src/main/java/com/zy/core/thread/SiemensDevpThread.java | 140 ++++++++++++++++++++++++++++++++-------------- 1 files changed, 96 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java index a8bde3c..85c82c1 100644 --- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java +++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java @@ -53,10 +53,12 @@ add(401);add(402); }}; + private Integer count=0; + /** * 鏉$爜鏁伴噺 */ - private int barcodeSize = 3; + private int barcodeSize = 4; /** * 鍏ュ嚭搴撴ā寮� @@ -123,26 +125,30 @@ * 鍒濆鍖栫珯鐐圭姸鎬� */ private void initSite() { + count ++; ArrayList<Integer> staNos = getStaNo(); - // 绔欑偣缂栧彿 - for (Integer siteId : staNos) { - StaProtocol staProtocol = station.get(siteId); - if (null == staProtocol) { - staProtocol = new StaProtocol(); - staProtocol.setSiteId(siteId); - station.put(siteId, staProtocol); - } - staProtocol.setWorkNo((short) 0); // ID - staProtocol.setAutoing(false); // 鑷姩 - staProtocol.setLoading(false); // 鏈夌墿 - staProtocol.setInEnable(false); // 鍙叆 - staProtocol.setOutEnable(false); // 鍙嚭 - staProtocol.setEmptyMk(false); // 绌烘澘淇″彿 - staProtocol.setStaNo((short) 0); // 鐩爣绔� + if(count > 10) { + // 绔欑偣缂栧彿 + for (Integer siteId : staNos) { + StaProtocol staProtocol = station.get(siteId); + if (null == staProtocol) { + staProtocol = new StaProtocol(); + staProtocol.setSiteId(siteId); + station.put(siteId, staProtocol); + } + staProtocol.setWorkNo((short) 0); // ID + staProtocol.setAutoing(false); // 鑷姩 + staProtocol.setLoading(false); // 鏈夌墿 + staProtocol.setInEnable(false); // 鍙叆 + staProtocol.setOutEnable(false); // 鍙嚭 + staProtocol.setEmptyMk(false); // 绌烘澘淇″彿 + staProtocol.setStaNo((short) 0); // 鐩爣绔� - if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { - staProtocol.setPakMk(true); + if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { + staProtocol.setPakMk(true); + } } + count = 0; } } @@ -204,38 +210,78 @@ // } // } Thread.sleep(200); - OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB100.100", (short) (staNoSize)); - if (result1.IsSuccess) { - for (int i = 0; i < staNoSize; i++) { - Integer siteId = staNos.get(i); // 绔欑偣缂栧彿 - boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i, 1); - StaProtocol staProtocol = station.get(siteId); - staProtocol.setAutoing(status[0]); // 鑷姩 - staProtocol.setLoading(status[1]); // 鏈夌墿 - staProtocol.setInEnable(status[2]); // 鍙叆 - staProtocol.setOutEnable(status[3]);// 鍙嚭 - staProtocol.setEmptyMk(status[4]); // 绌烘澘淇″彿 - staProtocol.setFullPlt(status[5]); // 婊℃墭鐩� - staProtocol.setHigh(status[6]); // 楂樺簱浣� - staProtocol.setLow(status[7]); // 浣庡簱浣� + OperateResultExOne<byte[]> result1 = null; + if(slave.getId()==1) { + result1 = siemensS7Net.Read("DB100.100", (short) (staNoSize)); + if (result1.IsSuccess) { + for (int i = 0; i < staNoSize; i++) { + Integer siteId = staNos.get(i); // 绔欑偣缂栧彿 + boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i, 1); + StaProtocol staProtocol = station.get(siteId); + staProtocol.setAutoing(status[0]); // 鑷姩 + staProtocol.setLoading(status[1]); // 鏈夌墿 + staProtocol.setInEnable(status[2]); // 鍙叆 + staProtocol.setOutEnable(status[3]);// 鍙嚭 + staProtocol.setEmptyMk(status[4]); // 绌烘澘淇″彿 + staProtocol.setFullPlt(status[5]); // 婊℃墭鐩� + staProtocol.setHigh(status[6]); // 楂樺簱浣� + staProtocol.setLow(status[7]); // 浣庡簱浣� - if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { - staProtocol.setPakMk(true); + if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { + staProtocol.setPakMk(true); + } + count = 0; } + } + } else if(slave.getId()==2) { + result1 = siemensS7Net.Read("DB100.100", (short) (staNoSize * 2)); + if (result1.IsSuccess) { + for (int i = 0; i < staNoSize; i++) { + Integer siteId = staNos.get(i); // 绔欑偣缂栧彿 + boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i * 2, 1); + StaProtocol staProtocol = station.get(siteId); + staProtocol.setAutoing(status[0]); // 鑷姩 + staProtocol.setLoading(status[1]); // 鏈夌墿 + staProtocol.setInEnable(status[2]); // 鍙叆 + staProtocol.setOutEnable(status[3]);// 鍙嚭 + staProtocol.setEmptyMk(status[4]); // 绌烘澘淇″彿 + staProtocol.setFullPlt(status[5]); // 婊℃墭鐩� + staProtocol.setHigh(status[6]); // 楂樺簱浣� + staProtocol.setLow(status[7]); // 浣庡簱浣� + + if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { + staProtocol.setPakMk(true); + } + } + count = 0; } } Thread.sleep(200); - OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.150",(short)(barcodeSize*8)); - 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); + if(slave.getId()==1) { + OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.150", (short) (barcodeSize * 8)); + 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); + } } - } + } + } else if(slave.getId()==2) { + OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.150", (short) (1 * 8)); + if (result2.IsSuccess) { + for (int i = 0; i < 1; i++) { + String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 8, 8, "UTF-8"); + BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 4); + if (!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { + barcodeThread.setBarcode(barcode); + } + } + + } } // OperateResultExOne<Short> result2 = siemensS7Net.ReadInt16("DB200.0"); @@ -243,7 +289,7 @@ // this.ioMode = IoModeType.get(result2.Content); // } - if (result.IsSuccess && result1.IsSuccess) { + if (result.IsSuccess && !Cools.isEmpty(result1) && result1.IsSuccess) { OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId())); @@ -305,12 +351,18 @@ // 鏇存柊鍏ュ嚭搴撴ā寮� private void updateIoMode() throws InterruptedException { - if (this.ioModeOf2F != IoModeType.NONE) { + if (slave.getId()==1 && this.ioModeOf2F != IoModeType.NONE) { if (!siemensS7Net.Write("DB100.180", this.ioModeOf2F.id).IsSuccess) { OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎2F鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={1}", slave.getId())); log.error("鍐欏叆杈撻�佺嚎2F鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={}", slave.getId()); } } + if (slave.getId()==2 && this.ioModeOf4F != IoModeType.NONE) { + if (!siemensS7Net.Write("DB100.170", this.ioModeOf4F.id).IsSuccess) { + OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎4F鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={1}", slave.getId())); + log.error("鍐欏叆杈撻�佺嚎4F鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={}", slave.getId()); + } + } } /** -- Gitblit v1.9.1