| | |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.BasDevpOpt; |
| | | import com.zy.asrs.entity.BasRgvMap; |
| | | import com.zy.asrs.entity.BasRgvOpt; |
| | | import com.zy.asrs.service.BasDevpOptService; |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.asrs.service.BasRgvMapService; |
| | | import com.zy.asrs.service.BasRgvOptService; |
| | | import com.zy.common.utils.News; |
| | | import com.zy.core.DevpThread; |
| | | import com.zy.core.cache.MessageQueue; |
| | |
| | | add(2016);add(2018); |
| | | add(2019);add(2021); |
| | | add(2022);add(2024); |
| | | add(2028);add(2030); |
| | | add(2025);add(2027); |
| | | add(2031);add(2033); |
| | | add(2034);add(2035);add(2037); |
| | | add(2041);add(2042);add(2043);add(2044); |
| | | add(2045);add(2046);add(2047);add(2048); |
| | | add(2101);add(2102);add(2103);add(2104);add(2105);add(2106);add(2107);add(2108);add(2109);add(2110); |
| | | add(2111);add(2112);add(2113);add(2114);add(2115);add(2116);add(2117);add(2118);add(2119);add(2120); |
| | | // add(2041);add(2042);add(2043);add(2044); |
| | | // add(2045);add(2046);add(2047);add(2048); |
| | | // add(2101);add(2102);add(2103);add(2104);add(2105);add(2106);add(2107);add(2108);add(2109);add(2110); |
| | | // add(2111);add(2112);add(2113);add(2114);add(2115);add(2116);add(2117);add(2118);add(2119);add(2120); |
| | | add(4001);add(4003);add(4004);add(4006); |
| | | }}; |
| | | |
| | |
| | | }}; |
| | | |
| | | public static final Map<Integer, Integer> siteErrOffsetMap = new HashMap<Integer, Integer>() {{ |
| | | put(1036, 512);put(1103, 476);put(1047, 452); |
| | | put(1036, 512);put(1103, 476);put(1047, 452);put(2037, 270);put(4001,294); |
| | | |
| | | }}; |
| | | |
| | | // 特殊站点集合 |
| | | private static final Set<Integer> specialSites = new HashSet<>( |
| | | Arrays.asList(1001,1005,1008,1011,1015,1019,1022,1025,1029, 1032,1039,2004,2001,2007,2010,2016,2013,2019,2022,2025,2030,4001,4004)); |
| | | Arrays.asList(1001,1005,1008,1011,1015,1019,1022,1025,1029, 1032,1039,2004,2001,2007,2010,2016,2013,2019,2022,2025,2028,4001,4004)); |
| | | |
| | | // 特殊站点集合 |
| | | private static final Set<Integer> specialSites2 = new HashSet<>( |
| | |
| | | public static final ArrayList<Integer> BarcodeList = new ArrayList<Integer>() {{ |
| | | add(0); add(1); add(2); |
| | | }}; |
| | | public static final ArrayList<Integer> BarcodeListMat = new ArrayList<Integer>() {{ |
| | | add(3); add(4); |
| | | public static final ArrayList<Integer> BarcodeList2 = new ArrayList<Integer>() {{ |
| | | add(3); add(4); add(5); |
| | | }}; |
| | | public static final ArrayList<Integer> staNosErrList = new ArrayList<Integer>() {{ |
| | | add(1103);add(1036);add(1047); |
| | | add(1103);add(1036);add(1047);add(2037); |
| | | }}; |
| | | |
| | | private Integer count=0; |
| | |
| | | public static int getOffsetBySiteId2(int siteId) { |
| | | int offset = 0; |
| | | if (specialSites.contains(siteId)) { |
| | | offset = 72; // 特殊站点占 96 |
| | | offset = 72; // 特殊站点占 72 |
| | | } else { |
| | | offset = 60; // 普通站点占 72 |
| | | offset = 60; // 普通站点占 60 |
| | | } |
| | | return offset; |
| | | } |
| | |
| | | return staNos1; |
| | | case 2: |
| | | return staNos2; |
| | | default: |
| | | throw new CoolException("服务器异常"); |
| | | } |
| | | } |
| | | |
| | | private ArrayList<Integer> getBarcodeList() { |
| | | switch (slave.getId()) { |
| | | case 1: |
| | | return BarcodeList; |
| | | case 2: |
| | | return BarcodeList2; |
| | | default: |
| | | throw new CoolException("服务器异常"); |
| | | } |
| | |
| | | OperateResultExOne<byte[]> result3 = null;//1042-1053 |
| | | OperateResultExOne<byte[]> result4 = null;//1054-1079 |
| | | OperateResultExOne<byte[]> result5 = null;//1080-1110 |
| | | OperateResultExOne<byte[]> resultErr = null;//1080-1110 |
| | | OperateResultExOne<byte[]> resultErr = null; |
| | | if(staNoSize == 99){ |
| | | result1 = siemensS7Net.Read("DB100.0", (short) (2768));//1001-1028 |
| | | result2 = siemensS7Net.Read("DB101.0", (short) (1268));//1029-1037 |
| | | result3 = siemensS7Net.Read("DB104.0", (short) (1268));//1042-1053 |
| | | result4 = siemensS7Net.Read("DB103.0", (short) (2824));//1054-1079 |
| | | result5 = siemensS7Net.Read("DB102.0", (short) (3428));//1080-1110 |
| | | resultErr = siemensS7Net.Read("DB3.0", (short) (536));//1080-1110 |
| | | resultErr = siemensS7Net.Read("DB3.0", (short) (536)); |
| | | }else{ |
| | | result1 = siemensS7Net.Read("DB200.0", (short) (3000));//2001-2030 |
| | | result2 = siemensS7Net.Read("DB201.0", (short) (720));//2031-2037 |
| | | result3 = siemensS7Net.Read("DB400.0", (short) (600));//4001-4006 |
| | | resultErr = siemensS7Net.Read("DB3.0", (short) (354)); |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setSiteId(siteId); |
| | | if (staNoSize == 99) { |
| | | if (siteId < 1029) { |
| | | result = result1; |
| | |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, offset + offset3, 1); |
| | | staProtocol.setAutoing(!status[0]); // 自动 |
| | | boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result.Content, offset + offset3 - 4, 3); |
| | | |
| | | staProtocol.setLoading(!status1[0]); // 有物 |
| | | boolean[] statusErr = siemensS7Net.getByteTransform().TransBool(result.Content, offset + 54, 1); |
| | | boolean loading = false; |
| | | if(!status1[0]) |
| | | // && statusErr[2]) |
| | | { |
| | | loading = true; |
| | | } |
| | | staProtocol.setLoading(loading); // 有物 |
| | | |
| | | staProtocol.setInEnable(status1[2]); // 可入 |
| | | staProtocol.setOutEnable(status1[2]);// 可出 |
| | |
| | | } |
| | | } |
| | | //条码扫描器 |
| | | ArrayList<Integer> barcodeList = BarcodeList; |
| | | OperateResultExOne<byte[]> reasultBarcode1 = siemensS7Net.Read("DB101.780", (short) 8);//1036 |
| | | OperateResultExOne<byte[]> reasultBarcode2 = siemensS7Net.Read("DB104.548", (short) 8);//1047 |
| | | OperateResultExOne<byte[]> reasultBarcode3 = siemensS7Net.Read("DB102.2780", (short) 8);//1103 |
| | | // OperateResultExOne<byte[]> reasultBarcode4 = siemensS7Net.Read("DB104.180", (short) 184); |
| | | if(reasultBarcode1.IsSuccess){ |
| | | Integer barcodeId = barcodeList.get(0); |
| | | String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode1.Content, 0)); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | // News.error(JSON.toJSONString(barcode+"线程"+barcodeId)); |
| | | |
| | | } |
| | | if(reasultBarcode2.IsSuccess){ |
| | | Integer barcodeId = barcodeList.get(1); |
| | | String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode2.Content, 0)); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | // News.error(JSON.toJSONString(barcode+"线程"+barcodeId)); |
| | | ArrayList<Integer> barcodeList = getBarcodeList(); |
| | | OperateResultExOne<byte[]> reasultBarcode1 = siemensS7Net.Read("DB101.780", (short) 4);//1036 |
| | | OperateResultExOne<byte[]> reasultBarcode2 = siemensS7Net.Read("DB104.548", (short) 4);//1047 |
| | | OperateResultExOne<byte[]> reasultBarcode3 = siemensS7Net.Read("DB102.2780", (short) 4);//1103 |
| | | OperateResultExOne<byte[]> reasultBarcode4 = siemensS7Net.Read("DB201.344", (short) 4);//2037 |
| | | OperateResultExOne<byte[]> reasultBarcode5 = siemensS7Net.Read("DB400.112", (short) 4);//4001 |
| | | |
| | | } |
| | | if(reasultBarcode3.IsSuccess){ |
| | | Integer barcodeId = barcodeList.get(2); |
| | | String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode3.Content, 0)); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | // News.error(JSON.toJSONString(barcode+"线程"+barcodeId)); |
| | | if(barcodeList.get(0) == 0){ |
| | | if(reasultBarcode1.IsSuccess){ |
| | | Integer barcodeId = barcodeList.get(0); |
| | | String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode1.Content, 0)); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | |
| | | } |
| | | if(reasultBarcode2.IsSuccess){ |
| | | Integer barcodeId = barcodeList.get(1); |
| | | String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode2.Content, 0)); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | |
| | | } |
| | | if(reasultBarcode3.IsSuccess){ |
| | | Integer barcodeId = barcodeList.get(2); |
| | | String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode3.Content, 0)); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | |
| | | } |
| | | }else if(barcodeList.get(0) == 3){ |
| | | if(reasultBarcode4.IsSuccess){ |
| | | Integer barcodeId = barcodeList.get(0); |
| | | String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode4.Content, 0)); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + +1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | if(reasultBarcode5.IsSuccess){ |
| | | Integer barcodeId = barcodeList.get(1); |
| | | String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode5.Content, 0)); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + +1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | log.error("写入输送线命令失败。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | } |
| | | }while (writeCount<5); |
| | | try { |
| | | // 日志记录 |
| | | BasDevpOptService bean = SpringUtils.getBean(BasDevpOptService.class); |
| | | BasDevpOpt basDevpOpt = new BasDevpOpt( |
| | | staProtocol.getWorkNo(), |
| | | new Date(), |
| | | staProtocol.getSiteId(), |
| | | (int)staProtocol.getStaNo(), |
| | | new Date(), |
| | | String.valueOf(staProtocol.isLoading()), |
| | | staProtocol.getBarcode(), |
| | | staProtocol.isFrontErr()? 1L:0L, |
| | | staProtocol.isBackErr()? 1L:0L, |
| | | staProtocol.isHighErr()? 1L:0L, |
| | | staProtocol.isLeftErr()? 1L:0L, |
| | | staProtocol.isRightErr()? 1L:0L, |
| | | staProtocol.isBarcodeErr()? 1L:0L |
| | | |
| | | ); |
| | | bean.insert(basDevpOpt); |
| | | } catch (Exception ignore) { |
| | | log.error(ignore.getMessage()); |
| | | } |
| | | |
| | | if (!write.IsSuccess) { |
| | | staProtocol = station.get(staProtocol.getSiteId()); |