From 964b8b59ad2a37c92bd3c738bf98d65e3916d0e7 Mon Sep 17 00:00:00 2001 From: whycq <123456> Date: 星期日, 07 七月 2024 13:27:02 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/SiemensDevpThread.java | 145 ++++++++++++++++++++++-------------------------- 1 files changed, 67 insertions(+), 78 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java index f0435a5..288fb99 100644 --- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java +++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java @@ -22,6 +22,7 @@ import com.zy.core.enums.SlaveType; import com.zy.core.model.DevpSlave; import com.zy.core.model.Task; +import com.zy.core.model.protocol.StaError1; import com.zy.core.model.protocol.StaProtocol; import lombok.Data; import lombok.extern.slf4j.Slf4j; @@ -45,6 +46,7 @@ private SiemensS7Net siemensS7Net; private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>(); private short heartBeatVal = 1; + private StaError1 staError1; // public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{ // // }}; @@ -55,25 +57,20 @@ add(112);add(113);add(114);add(115); add(116);add(117);add(118);add(119); add(120);add(121);add(122);add(123); - add(124);add(125);add(126);add(127); - add(128);add(129);add(130);add(131); - add(132);add(133);add(134);add(135); - add(136);add(137);add(138);add(139); - add(140);add(141);add(142);add(143); - add(144);add(145);add(146);add(147); - add(148);add(149);add(150);add(151); - add(152);add(153);add(154);add(155); - add(156);add(157);add(158);add(159); - add(160);add(161); - add(1); -// add(200);add(201);add(202); + + add(200);add(201);add(202);add(203); + add(204);add(205);add(206);add(207); + add(208);add(209);add(210);add(211); + add(212);add(213);add(214);add(215); + add(216);add(217);add(218);add(219); + add(220);add(221);add(222);add(223); }}; public static final ArrayList<Integer> BarcodeList = new ArrayList<Integer>() {{ - add(0); add(1); add(2); + add(1); add(2); }}; public static final ArrayList<Integer> staNosErrList = new ArrayList<Integer>() {{ - add(106); add(107); add(159); + add(101); add(201); }}; private Integer count=0; @@ -81,7 +78,7 @@ /** * 鏉$爜鏁伴噺 */ - private int barcodeSize = 6; + private int barcodeSize = 2; /** * 鍏ュ嚭搴撴ā寮� @@ -135,7 +132,7 @@ } // 蹇冭烦 // heartbeat(); - Thread.sleep(300); + Thread.sleep(100); } catch (Exception e) { e.printStackTrace(); } @@ -148,7 +145,7 @@ private void initSite() { count ++; ArrayList<Integer> staNos = getStaNo(); - if(count > 77) { + if(count > 48) { // 绔欑偣缂栧彿 for (Integer siteId : staNos) { StaProtocol staProtocol = station.get(siteId); @@ -202,6 +199,7 @@ ArrayList<Integer> staNos = getStaNo(); int staNoSize = staNos.size(); OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (staNoSize*8)); + OperateResultExOne<byte[]> result200 = siemensS7Net.Read("DB101.800", (short) (staNoSize*8)); if (result.IsSuccess) { for (int i = 0; i < staNoSize; i++) { Integer siteId = staNos.get(i); // 绔欑偣缂栧彿 @@ -211,11 +209,21 @@ staProtocol.setSiteId(siteId); station.put(siteId, staProtocol); } - staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result.Content, i*8)); // 宸ヤ綔鍙� + boolean[] status = null; + if(i < 24){ + staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result.Content, i*8)); // 宸ヤ綔鍙� - staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*8 + 4)); // 鐩爣绔� + staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*8 + 4)); // 鐩爣绔� - boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, i*8 + 6, 2); + status = siemensS7Net.getByteTransform().TransBool(result.Content, i*8 + 6, 2); + }else { + staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result200.Content, (i-24)*8)); // 宸ヤ綔鍙� + + staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result200.Content, (i-24)*8 + 4)); // 鐩爣绔� + + status = siemensS7Net.getByteTransform().TransBool(result200.Content, (i-24)*8 + 6, 2); + } + staProtocol.setAutoing(status[0]); // 鑷姩 staProtocol.setLoading(status[1]); // 鏈夌墿 staProtocol.setInEnable(status[2]); // 鍙叆 @@ -230,68 +238,15 @@ } } } - BasRgvMapService basRgvMapService = SpringUtils.getBean(BasRgvMapService.class); - //RGV灏忚溅1 - Thread.sleep(100); - OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB50.200",(short)10); - if (result3.IsSuccess) { - BasRgvMap basRgvMap = basRgvMapService.selectByRgvNo((int) siemensS7Net.getByteTransform().TransInt16(result3.Content, 0)); - if (!Cools.isEmpty(basRgvMap)){ - Integer siteId = 1; - StaProtocol staProtocol = station.get(siteId); - if (null == staProtocol) { - staProtocol = new StaProtocol(); - staProtocol.setSiteId(siteId); - station.put(siteId, staProtocol); - } - staProtocol.setAutoing(true); - staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result3.Content, 8))); - } - } - //RGV灏忚溅2 - Thread.sleep(100); - OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB50.212",(short)10); - if (result4.IsSuccess) { - BasRgvMap basRgvMap = basRgvMapService.selectByRgvNo((int) siemensS7Net.getByteTransform().TransInt16(result4.Content, 0)); - if (!Cools.isEmpty(basRgvMap)){ - Integer siteId = 2; - StaProtocol staProtocol = station.get(siteId); - if (null == staProtocol) { - staProtocol = new StaProtocol(); - staProtocol.setSiteId(siteId); - station.put(siteId, staProtocol); - } - staProtocol.setAutoing(true); - staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result4.Content, 8))); - } - } - - //RGV灏忚溅3 - Thread.sleep(100); - OperateResultExOne<byte[]> result5 = siemensS7Net.Read("DB50.224",(short)10); - if (result5.IsSuccess) { - BasRgvMap basRgvMap = basRgvMapService.selectByRgvNo((int) siemensS7Net.getByteTransform().TransInt16(result5.Content, 0)); - if (!Cools.isEmpty(basRgvMap)){ - Integer siteId = 3; - StaProtocol staProtocol = station.get(siteId); - if (null == staProtocol) { - staProtocol = new StaProtocol(); - staProtocol.setSiteId(siteId); - station.put(siteId, staProtocol); - } - staProtocol.setAutoing(true); - staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result5.Content, 8))); - } - } //鏉$爜鎵弿鍣� ArrayList<Integer> barcodeList = BarcodeList; - OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.840", (short) (barcodeList.size() * 8)); + OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.1648", (short) (barcodeList.size() * 8)); if (result2.IsSuccess) { 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, barcodeId + 1); + BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId); if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { barcodeThread.setBarcode(barcode); } @@ -300,9 +255,9 @@ //澶栧舰妫�娴� ArrayList<Integer> staNoErrs = staNosErrList; int staNoErrsSize = staNoErrs.size(); - OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.800", (short) (staNoErrsSize*8)); + OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.1608", (short) (staNoErrsSize*8)); if (resultErr.IsSuccess){ - for (int i = 0;i<3;i++){ + for (int i = 0;i<2;i++){ Integer siteId = staNoErrs.get(i); // 绔欑偣缂栧彿 boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*4+2, 1); StaProtocol staProtocol = station.get(siteId); @@ -316,7 +271,8 @@ } } - OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB13.2", (short) (staNoSize*4)); + //plc鏁呴殰 + OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB101.1728", (short) (staNoSize*4)); if (resultErr2.IsSuccess) { for (int i = 0; i < staNoSize; i++) { Integer siteId = staNos.get(i); // 绔欑偣缂栧彿 @@ -332,6 +288,33 @@ staProtocol.setUpcontactErr(status[7]); } + } + OperateResultExOne<byte[]> resultErr3 = siemensS7Net.Read("DB13.400", (short) 3); + if (resultErr3.IsSuccess) { + if (staError1 == null){ + staError1 = new StaError1(); + } + boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr3.Content, 0, 3); + staError1.setEMERGENCY_Stop_Core(status[0]); + staError1.setEMERGENCY_STOP1(status[1]); + staError1.setEMERGENCY_STOP2(status[2]); + staError1.setEMERGENCY_STOP3(status[3]); + staError1.setEMERGENCY_STOP4(status[4]); + + staError1.setDoor_EMERGENCY_STOP1(status[5]); + staError1.setDoor_EMERGENCY_STOP2(status[6]); + staError1.setDoor_EMERGENCY_STOP3(status[7]); + staError1.setDoor_EMERGENCY_STOP4(status[8]); + staError1.setDoor_EMERGENCY_STOP5(status[9]); + staError1.setDoor_EMERGENCY_STOP6(status[10]); + + staError1.setDoor_Open_Err1(status[11]); + staError1.setDoor_Open_Err1(status[12]); + staError1.setDoor_Open_Err1(status[13]); + staError1.setDoor_Open_Err1(status[14]); + staError1.setDoor_Open_Err1(status[15]); + staError1.setDoor_Open_Err1(status[16]); + } @@ -373,6 +356,11 @@ } ArrayList<Integer> staNos = getStaNo(); int index = staNos.indexOf(staProtocol.getSiteId()); + + if(index >= 24){ + index = 76 + index; + } + OperateResult write = null; OperateResult write1 = null; //浠诲姟涓嬪彂娆℃暟 @@ -382,6 +370,7 @@ Thread.sleep(200); write1 = siemensS7Net.Write("DB100." + (index*6+4), staProtocol.getStaNo().shortValue()); // 鐩爣绔� if(write.IsSuccess && write1.IsSuccess){ + log.error("鍐欏叆杈撻�佺嚎鍛戒护鎴愬姛銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); break; } else { -- Gitblit v1.9.1