|  |  | 
 |  |  | import HslCommunication.Profinet.Siemens.SiemensPLCS; | 
 |  |  | import HslCommunication.Profinet.Siemens.SiemensS7Net; | 
 |  |  | import com.alibaba.fastjson.JSON; | 
 |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
 |  |  | import com.core.common.Cools; | 
 |  |  | import com.core.common.DateUtils; | 
 |  |  | import com.core.common.SpringUtils; | 
 |  |  | import com.core.exception.CoolException; | 
 |  |  | import com.zy.entity.BasDevp; | 
 |  |  | import com.zy.entity.BasRgvMap; | 
 |  |  | import com.zy.service.BasDevpService; | 
 |  |  | import com.zy.service.BasRgvMapService; | 
 |  |  | import com.zy.utils.News; | 
 |  |  | import com.zy.core.DevpThread; | 
 |  |  | import com.zy.core.cache.MessageQueue; | 
 |  |  | import com.zy.core.cache.OutputQueue; | 
 |  |  | import com.zy.core.cache.SlaveConnection; | 
 |  |  | import com.zy.core.enums.IoModeType; | 
 |  |  | 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 com.zy.entity.BasDevp; | 
 |  |  | import com.zy.service.BasDevpService; | 
 |  |  | import com.zy.system.entity.Config; | 
 |  |  | import com.zy.system.service.ConfigService; | 
 |  |  | import com.zy.utils.News; | 
 |  |  | import lombok.Data; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  |  | 
 |  |  | import java.text.MessageFormat; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Map; | 
 |  |  | import java.util.*; | 
 |  |  | import java.util.concurrent.ConcurrentHashMap; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  | 
 |  |  |     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>() {{ | 
 |  |  | // | 
 |  |  | //    }}; | 
 |  |  |  | 
 |  |  |     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); | 
 |  |  |         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(1001);add(1002);add(1004);add(1005);add(1006);add(1007);add(1008);add(1009);add(1010);add(1011);add(1012); | 
 |  |  |         add(1018);add(1017);add(1016);add(1015);add(1014);add(1020);add(1019);add(1013);add(1043);add(1042);add(1041); | 
 |  |  |         add(1022);add(1023);add(1024);add(1025);add(1026);add(1027);add(1028);add(1030);add(1031);add(1032);add(1033); | 
 |  |  |         add(1034);add(1035);add(1036);add(1038);add(1039);add(1040); | 
 |  |  |     }}; | 
 |  |  |  | 
 |  |  |     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); | 
 |  |  |     public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{ | 
 |  |  |         add(1044);add(1045);add(1046);add(1047);add(1048);add(1049);add(1050);add(1051);add(1052);add(1053);add(1054);add(1055);add(1056);add(1057);add(1058); | 
 |  |  |         add(1061);add(1062);add(1066);add(1067);add(1068);add(1069);add(1070);add(1071);add(1072);add(1063);add(1064);add(1065); | 
 |  |  |         add(1073);add(1074);add(1075);add(1076);add(1077);add(1078);add(1079); | 
 |  |  |         add(1081);add(1082);add(1083);add(1084);add(1085);add(1086);add(1087);add(1088);add(1089);add(1090); | 
 |  |  |     }}; | 
 |  |  |  | 
 |  |  |     private Integer count=0; | 
 |  |  |     public static final ArrayList<Integer> staNos3 = new ArrayList<Integer>() {{ | 
 |  |  |         add(1091);add(1092);add(1093);add(1094);add(1095);add(1096);add(1097);add(1098);add(1099);add(1100);add(1101);add(1102); | 
 |  |  |         add(1103);add(1104);add(1105);add(1106);add(1107); | 
 |  |  |     }}; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 条码数量 | 
 |  |  |      */ | 
 |  |  |     private int barcodeSize = 6; | 
 |  |  |     public static final ArrayList<Integer> rgvSiteBackWrkNo1= new ArrayList<Integer>() {{ | 
 |  |  |         add(1001);add(1006);add(1012);add(1018);add(1019);add(1041);add(1022);add(1026);add(1033);add(1034); | 
 |  |  |     }}; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 入出库模式 | 
 |  |  |      * 0:未知 | 
 |  |  |      * 1:入库启动中 | 
 |  |  |      * 2.入库模式 | 
 |  |  |      * 3.出库启动中 (不能生成入库工作档) | 
 |  |  |      * 4.出库模式 | 
 |  |  |      */ | 
 |  |  |     public IoModeType ioModeOf2F = IoModeType.NONE; | 
 |  |  | //    public IoModeType ioMode = IoModeType.NONE; | 
 |  |  |     public IoModeType ioModeOf4F = IoModeType.NONE; | 
 |  |  | //    public IoModeType ioMode = IoModeType.NONE; | 
 |  |  |     public static final ArrayList<Integer> rgvSiteBackWrkNo2= new ArrayList<Integer>() {{ | 
 |  |  |         add(1044);add(1090); | 
 |  |  |     }}; | 
 |  |  |  | 
 |  |  |     public static final ArrayList<Integer> rgvSiteBackWrkNo3= new ArrayList<Integer>() {{ | 
 |  |  |         add(1105);add(1100);add(1091);add(1094);add(1097); | 
 |  |  |     }}; | 
 |  |  |  | 
 |  |  |     public static final ArrayList<Integer> barcodeList = new ArrayList<Integer>() {{ | 
 |  |  |         add(1); add(2); add(3); add(4); | 
 |  |  |     }}; | 
 |  |  |  | 
 |  |  |     // 外形检测1号plc | 
 |  |  |     public static final ArrayList<Integer> staNosErrList1 = new ArrayList<Integer>() {{ | 
 |  |  |         add(1006); add(1012);add(1018);add(1041); | 
 |  |  |     }}; | 
 |  |  |  | 
 |  |  |     // 外形检测2号plc | 
 |  |  |     public static final ArrayList<Integer> staNosErrList2 = new ArrayList<Integer>() {{ | 
 |  |  |         add(1083); add(1086);add(1089); | 
 |  |  |     }}; | 
 |  |  |  | 
 |  |  |     // 出罐装线反馈给wcs信息站点 | 
 |  |  |     public static final ArrayList<Integer> gzxResultSite = new ArrayList<Integer>() {{ | 
 |  |  |         add(1081); add(1084);add(1087); | 
 |  |  |     }}; | 
 |  |  |  | 
 |  |  |     private static long lastLogTime = 0; | 
 |  |  |  | 
 |  |  |     public SiemensDevpThread(DevpSlave slave) { | 
 |  |  |         this.slave = slave; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private ArrayList<Integer> getStaNo() { | 
 |  |  |         switch (slave.getId()) { | 
 |  |  |             case 1: | 
 |  |  |                 return staNos1; | 
 |  |  |     private ArrayList<Integer> getRgvSiteBackWrkNo() { | 
 |  |  |         switch (this.slave.getId()) { | 
 |  |  |             case 1: return rgvSiteBackWrkNo1; | 
 |  |  |             case 2: return rgvSiteBackWrkNo2; | 
 |  |  |             case 3: return rgvSiteBackWrkNo3; | 
 |  |  |             default: | 
 |  |  |                 throw new CoolException("服务器异常"); | 
 |  |  |         } | 
 |  |  |         return new ArrayList<>(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private ArrayList<Integer> getStaNo() { | 
 |  |  |         switch (this.slave.getId()) { | 
 |  |  |             case 1: return staNos1; | 
 |  |  |             case 2: return staNos2; | 
 |  |  |             case 3: return staNos3; | 
 |  |  |             default: | 
 |  |  |         } | 
 |  |  |         return new ArrayList<>(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private ArrayList<Integer> getStaNosErrList() { | 
 |  |  |         switch (this.slave.getId()) { | 
 |  |  |             case 1: return staNosErrList1; | 
 |  |  |             case 2: return staNosErrList2; | 
 |  |  |             default: | 
 |  |  |         } | 
 |  |  |         return new ArrayList<>(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  | 
 |  |  |                     // 写数据 ID+目标站 | 
 |  |  |                     case 2: | 
 |  |  |                         write((StaProtocol)task.getData()); | 
 |  |  |                         log.error("输送线下发命令:"+((StaProtocol) task.getData()).getWorkNo()+","+((StaProtocol) task.getData()).getStaNo()); | 
 |  |  |                         break; | 
 |  |  |                     // 写尾桶信号 | 
 |  |  |                     case 3: | 
 |  |  |                         writeTail((StaProtocol)task.getData()); | 
 |  |  |                         break; | 
 |  |  |                     // 写入罐装线桶型信息 | 
 |  |  |                     case 4: | 
 |  |  |                         writeGzx((StaProtocol)task.getData()); | 
 |  |  |                         break; | 
 |  |  |                     // 给罐装线写可出 | 
 |  |  |                     case 5: | 
 |  |  |                         writeGzxkc((StaProtocol)task.getData()); | 
 |  |  |                         break; | 
 |  |  |                     // 给罐装线写罐装数量 | 
 |  |  |                     case 6: | 
 |  |  |                         writeGzsl((StaProtocol)task.getData()); | 
 |  |  |                         break; | 
 |  |  |                     default: | 
 |  |  |                         break; | 
 |  |  | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 初始化站点状态 | 
 |  |  |      */ | 
 |  |  |     private void initSite() { | 
 |  |  |         count ++; | 
 |  |  |         ArrayList<Integer> staNos = getStaNo(); | 
 |  |  |         if(count > 77) { | 
 |  |  |             // 站点编号 | 
 |  |  |             for (Integer siteId : staNos) { | 
 |  |  |                 StaProtocol staProtocol = station.get(siteId); | 
 |  |  | 
 |  |  |                     staProtocol.setPakMk(true); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             count = 0; | 
 |  |  |  | 
 |  |  |         // 根据实时信息更新数据库 | 
 |  |  |         try { | 
 |  |  |             List<BasDevp> basDevps = new ArrayList<>(); | 
 |  |  |             for (Integer siteId2 : staNos) { | 
 |  |  |                 StaProtocol staProtocol2 = station.get(siteId2); | 
 |  |  |                 basDevps.add(staProtocol2.toSqlModel()); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); | 
 |  |  |             if(basDevps.size() > 0) { | 
 |  |  |                 if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) { | 
 |  |  |                     throw new Exception("更新数据库数据失败"); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |         } catch (Exception e){ | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |     /** | 
 |  |  |      * 读取状态 ====> 整块plc | 
 |  |  |      */ | 
 |  |  |     private void read() throws InterruptedException { | 
 |  |  | //        // 更新入出库模式 | 
 |  |  | //        updateIoMode(); | 
 |  |  |     private void read() { | 
 |  |  |  | 
 |  |  |         // 读罐装线反馈信息 | 
 |  |  |         if (slave.getId() > 3) { | 
 |  |  | //            log.info("读取{}号罐装线plc信息成功",slave.getId()); | 
 |  |  |             OperateResultExOne<byte[]> read = siemensS7Net.Read("DB101.0", (short) 64); | 
 |  |  |             if (read.IsSuccess) { | 
 |  |  |                 // 15秒打印一下日志 | 
 |  |  | //                if (System.currentTimeMillis() - lastLogTime >= 30000) { | 
 |  |  | //                    OperateResultExOne<byte[]> readKc = siemensS7Net.Read("DB100.6", (short) 4); | 
 |  |  | //                    if(readKc.IsSuccess){ | 
 |  |  | //                        short i = siemensS7Net.getByteTransform().TransInt16(readKc.Content, 0); | 
 |  |  | //                        short wantBucketCount = siemensS7Net.getByteTransform().TransInt16(readKc.Content, 2); | 
 |  |  | //                        log.info("读{}号罐装线可出信号成功,值:{},剩余要桶数量:{}", slave.getId() -3, i, wantBucketCount); | 
 |  |  | //                    } | 
 |  |  | //                    lastLogTime = System.currentTimeMillis(); | 
 |  |  | //                } | 
 |  |  |                 // 成品信息反馈到罐装线出口站点 | 
 |  |  |                 DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 2); | 
 |  |  |                 StaProtocol staProtocol = devpThread.getStation().get(gzxResultSite.get(slave.getId()-4)); | 
 |  |  |                 if (staProtocol != null) { | 
 |  |  |                     staProtocol.setWantBucketFlag(siemensS7Net.getByteTransform().TransInt16(read.Content, 0));// 罐装线要桶型信号 | 
 |  |  |                     OperateResultExOne<byte[]> read2 = siemensS7Net.Read("DB100.8", (short) 2); // 罐装线罐装数量(拖) | 
 |  |  |                     if(read2.IsSuccess){ | 
 |  |  |                         staProtocol.setWantBucketCount(siemensS7Net.getByteTransform().TransInt16(read2.Content, 0)); | 
 |  |  |                     } else { | 
 |  |  |                         log.error("读{}号罐装线要拖数量失败", slave.getId() -3); | 
 |  |  |                     } | 
 |  |  |                     staProtocol.setWrkNo(siemensS7Net.getByteTransform().TransInt16(read.Content, 2)); | 
 |  |  |                     double weight208l1 = siemensS7Net.getByteTransform().TransSingle(read.Content, 4); // 200L桶1净重 | 
 |  |  |                     double weight208l2 = siemensS7Net.getByteTransform().TransSingle(read.Content, 8); // 200L桶2净重 | 
 |  |  |                     double weight208l3 = siemensS7Net.getByteTransform().TransSingle(read.Content, 12); // 200L桶3净重 | 
 |  |  |                     double weight208l4 = siemensS7Net.getByteTransform().TransSingle(read.Content, 16); // 200L桶4净重 | 
 |  |  |                     double weight1T = siemensS7Net.getByteTransform().TransSingle(read.Content, 20); // 1T桶净重 | 
 |  |  | //                    log.info("读取工罐装线净重 200l桶1:{},200l桶2:{},200l桶3:{},200l桶4:{},1t桶:{}",weight208l1,weight208l2,weight208l3,weight208l4,weight1T); | 
 |  |  |                     staProtocol.setWeight(weight208l1 + weight208l2 + weight208l3 + weight208l4 + weight1T); | 
 |  |  |                     staProtocol.setGrossWeight(siemensS7Net.getByteTransform().TransSingle(read.Content, 24)); | 
 |  |  |                     staProtocol.setMatnr(siemensS7Net.getByteTransform().TransString(read.Content, 28,12,"UTF-8")); | 
 |  |  |                     staProtocol.setBatch(siemensS7Net.getByteTransform().TransString(read.Content, 40,10,"UTF-8")); | 
 |  |  |                     staProtocol.setManuDate(siemensS7Net.getByteTransform().TransString(read.Content, 50,8,"UTF-8")); | 
 |  |  |                     staProtocol.setReinspection(siemensS7Net.getByteTransform().TransInt16(read.Content, 58) == 1); | 
 |  |  |                     staProtocol.setCannedVolume(siemensS7Net.getByteTransform().TransSingle(read.Content, 60)); | 
 |  |  |                 } | 
 |  |  |                 return; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         ArrayList<Integer> staNos = getStaNo(); | 
 |  |  |         int staNoSize = staNos.size(); | 
 |  |  |         OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (staNoSize*8)); | 
 |  |  |         if (result.IsSuccess) { | 
 |  |  |             for (int i = 0; i < staNoSize; i++) { | 
 |  |  |         if(staNos == null) { | 
 |  |  |             log.error("读取plc地址块,获取站点列表失败"); | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 读站点信息反馈 | 
 |  |  |         OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (staNos.size() * 8)); | 
 |  |  |         if (result.IsSuccess)   { | 
 |  |  |             for (int i = 0; i < staNos.size(); i++) { | 
 |  |  |                 Integer siteId = staNos.get(i); // 站点编号 | 
 |  |  |                 StaProtocol staProtocol = station.get(siteId); | 
 |  |  |                 if (null == staProtocol) { | 
 |  |  | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         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)); | 
 |  |  |         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); | 
 |  |  |                 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]); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB13.2", (short) (staNoSize*4)); | 
 |  |  |         // 读故障信息反馈 | 
 |  |  |         OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB101.920", (short) (staNos.size()*4)); | 
 |  |  |         if (resultErr2.IsSuccess) { | 
 |  |  |             for (int i = 0; i < staNoSize; i++) { | 
 |  |  |                 Integer siteId = staNos.get(i); // 站点编号 | 
 |  |  |                 boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr2.Content, i*4, 1); | 
 |  |  |                 StaProtocol staProtocol = station.get(siteId); | 
 |  |  |             for (int i = 0; i < staNos.size(); i++) { | 
 |  |  |                 boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr2.Content, i * 4 + 2, 1); | 
 |  |  |                 StaProtocol staProtocol = station.get(staNos.get(i)); // 站点编号 | 
 |  |  |                 staProtocol.setBreakerErr(status[0]); | 
 |  |  |                 staProtocol.setInfraredErr(status[1]); | 
 |  |  |                 staProtocol.setOutTimeErr(status[2]); | 
 |  |  | 
 |  |  |  | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         OperateResultExOne<byte[]> resultErr3 = siemensS7Net.Read("DB13.400", (short) 3); | 
 |  |  |         if (resultErr3.IsSuccess) { | 
 |  |  |             if (staError1 == null){ | 
 |  |  |                 staError1 = new StaError1(); | 
 |  |  |  | 
 |  |  |         // 读rgv放货站点任务号反馈 | 
 |  |  |         ArrayList<Integer> rgvSiteBackWrkNo = getRgvSiteBackWrkNo(); | 
 |  |  |         OperateResultExOne<byte[]> rgvSiteBackWrkNoResult = siemensS7Net.Read("DB101.1440", (short) (rgvSiteBackWrkNo.size() * 2)); | 
 |  |  |         if (rgvSiteBackWrkNoResult.IsSuccess) { | 
 |  |  |             for (int i = 0; i < rgvSiteBackWrkNo.size(); i ++ ){ | 
 |  |  |                 short hideWrkNo = siemensS7Net.getByteTransform().TransInt16(rgvSiteBackWrkNoResult.Content, i * 2); | 
 |  |  |                 StaProtocol staProtocol = station.get(getRgvSiteBackWrkNo().get(i)); | 
 |  |  |                 staProtocol.setHideWorkNo((int) hideWrkNo); | 
 |  |  |             } | 
 |  |  |             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]); | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 读条码扫描器 | 
 |  |  |         if(slave.getId() == 1) { | 
 |  |  |             OperateResultExOne<byte[]> barcodeResult = siemensS7Net.Read("DB101.840", (short) (barcodeList.size() * 8)); | 
 |  |  |             if (barcodeResult.IsSuccess) { | 
 |  |  |                 for (int i = 0; i < barcodeList.size(); i++) { | 
 |  |  |                     String barcode = siemensS7Net.getByteTransform().TransString(barcodeResult.Content,i*8,8, "UTF-8"); | 
 |  |  |                     BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeList.get(i)); | 
 |  |  |                     if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { | 
 |  |  |                         barcodeThread.setBarcode(barcode); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 读1号输送线出入库模式 | 
 |  |  |         if (slave.getId() == 1) { | 
 |  |  |             OperateResultExOne<byte[]> inOrOutBoundModeResult = siemensS7Net.Read("DB101.1480", (short) 2); | 
 |  |  |             if (inOrOutBoundModeResult.IsSuccess) { | 
 |  |  |                 // 出入库模式 | 
 |  |  |                 int inOrOutMode = siemensS7Net.getByteTransform().TransInt16(inOrOutBoundModeResult.Content, 0); | 
 |  |  |                 // 更新出入库模式值 | 
 |  |  |                 ConfigService configService = SpringUtils.getBean(ConfigService.class); | 
 |  |  |                 Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "inOrOutBoundMode")); | 
 |  |  |                 if (config != null) { | 
 |  |  |                     config.setValue(String.valueOf(inOrOutMode)); | 
 |  |  |                     configService.updateById(config); | 
 |  |  |                 } | 
 |  |  |                 StaProtocol staProtocol1016 = station.get(1016); | 
 |  |  |                 StaProtocol staProtocol1043 = station.get(1043); | 
 |  |  |                 StaProtocol staProtocol1019 = station.get(1019); | 
 |  |  |                 if(staProtocol1016 != null) { | 
 |  |  |                     staProtocol1016.setInOrOutMode(inOrOutMode); | 
 |  |  |                 } | 
 |  |  |                 if(staProtocol1043 != null) { | 
 |  |  |                     staProtocol1043.setInOrOutMode(inOrOutMode); | 
 |  |  |                 } | 
 |  |  |                 if(staProtocol1019 != null) { | 
 |  |  |                     staProtocol1019.setInOrOutMode(inOrOutMode); | 
 |  |  |                 } | 
 |  |  | //                log.info("读取到出入库模式值为:{}",inOrOutMode); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 读空桶信息反馈 | 
 |  |  |         if (slave.getId() == 1) { | 
 |  |  |             OperateResultExOne<byte[]> emptyBucketsResult = siemensS7Net.Read("DB101.1320", (short) (staNosErrList1.size() * 6)); | 
 |  |  |             if (emptyBucketsResult.IsSuccess) { | 
 |  |  |                 for (int i = 0; i < staNosErrList1.size(); i++) { | 
 |  |  |                     // 桶类型标识 | 
 |  |  |                     int bucketType = siemensS7Net.getByteTransform().TransInt16(emptyBucketsResult.Content, i * 6); | 
 |  |  |                     // 桶数量 | 
 |  |  |                     int bucketCount = siemensS7Net.getByteTransform().TransInt16(emptyBucketsResult.Content, i * 6 + 2); | 
 |  |  |                     // 尾桶标识 | 
 |  |  |                     boolean[] tailSupportArray= siemensS7Net.getByteTransform().TransBool(emptyBucketsResult.Content, i * 6 + 4,1); | 
 |  |  |                     boolean tailSupportFlag = tailSupportArray[0]; | 
 |  |  | //                    log.info("空桶信息反馈,站点:{},桶类型标识:{},数量:{},尾桶标识:{}",staNosErrList1.get(i),bucketType,bucketCount,tailSupportFlag); | 
 |  |  |                     StaProtocol staProtocol = station.get(staNosErrList1.get(i)); | 
 |  |  |                     if (null == staProtocol) { | 
 |  |  |                         staProtocol = new StaProtocol(); | 
 |  |  |                         staProtocol.setSiteId(staNosErrList1.get(i)); | 
 |  |  |                         station.put(staNosErrList1.get(i), staProtocol); | 
 |  |  |                     } | 
 |  |  |                     staProtocol.setBucketType(String.valueOf(bucketType)); | 
 |  |  |                     staProtocol.setBucketCount(bucketCount); | 
 |  |  |                     staProtocol.setTailSupportFlag(tailSupportFlag); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 读外形检测 | 
 |  |  |         ArrayList<Integer> staNosErrList = getStaNosErrList(); | 
 |  |  |         OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.800", (short) (staNosErrList.size()*4)); | 
 |  |  |         if (resultErr.IsSuccess){ | 
 |  |  |             for (int i = 0;i<staNosErrList.size();i++){ | 
 |  |  |                 boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*4+2, 1); | 
 |  |  |                 StaProtocol staProtocol = station.get(staNosErrList.get(i)); | 
 |  |  |                 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 (result.IsSuccess) { | 
 |  |  |  | 
 |  |  | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); | 
 |  |  |                 if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) { | 
 |  |  |                     throw new Exception("更新数据库数据失败"); | 
 |  |  |                 if(basDevps.size() > 0) { | 
 |  |  |                     if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) { | 
 |  |  |                         throw new Exception("更新数据库数据失败"); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |             } catch (Exception e) { | 
 |  |  |                 initSite(); | 
 |  |  |                 e.printStackTrace(); | 
 |  |  | 
 |  |  |         if (null == staProtocol) { | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |         ArrayList<Integer> staNos = getStaNo(); | 
 |  |  |         int index = staNos.indexOf(staProtocol.getSiteId()); | 
 |  |  |         OperateResult write = null; | 
 |  |  |         OperateResult write1 = null; | 
 |  |  |  | 
 |  |  |         // 取站点下标,计算plc偏移量 | 
 |  |  |         int i = getStaNo().indexOf(staProtocol.getSiteId()); | 
 |  |  |  | 
 |  |  |         OperateResult write; | 
 |  |  |         OperateResult write1; | 
 |  |  |         //任务下发次数 | 
 |  |  |         int writeCount = 0; | 
 |  |  |         do { | 
 |  |  |             write = siemensS7Net.Write("DB100." + index*6, staProtocol.getWorkNo());    // 工作号 | 
 |  |  |             write1 = siemensS7Net.Write("DB100." + (i*6 +4), staProtocol.getStaNo());    // 目标站 | 
 |  |  |             write = siemensS7Net.Write("DB100." + (i*6), staProtocol.getWorkNo());    // 工作号 | 
 |  |  |             Thread.sleep(200); | 
 |  |  |             write1 = siemensS7Net.Write("DB100." + (index*6+4), staProtocol.getStaNo().shortValue());    // 目标站 | 
 |  |  |             if(write.IsSuccess && write1.IsSuccess){ | 
 |  |  |                 log.info("输送线命令下发成功,站点:{},任务号:{},目标站:{}",staProtocol.getSiteId(),staProtocol.getWorkNo(),staProtocol.getStaNo()); | 
 |  |  |                 break; | 
 |  |  |             } | 
 |  |  |             else { | 
 |  |  | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol))); | 
 |  |  |             News.info("SiemensDevp"+" - 5"+" - 输送线命令下发 [id:{}] >>>>> 命令下发: {}",  slave.getId(), JSON.toJSON(staProtocol)); | 
 |  |  |         } | 
 |  |  |         read(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     // 更新入出库模式 | 
 |  |  |     private void updateIoMode() throws InterruptedException { | 
 |  |  |         if (this.ioModeOf2F != IoModeType.NONE) { | 
 |  |  |             if (!siemensS7Net.Write("DB100.180", this.ioModeOf2F.id).IsSuccess) { | 
 |  |  |                 OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线2F入出库模式失败。输送线plc编号={1}", slave.getId())); | 
 |  |  |                 News.error("SiemensDevp"+" - 6"+" - 写入输送线2F入出库模式失败。输送线plc编号={}", slave.getId()); | 
 |  |  |     /** | 
 |  |  |      * 写尾桶信号 | 
 |  |  |      */ | 
 |  |  |     private void writeTail(StaProtocol staProtocol) throws InterruptedException { | 
 |  |  |         if (null == staProtocol) { | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         OperateResult write; | 
 |  |  |         //任务下发次数 | 
 |  |  |         int writeCount = 0; | 
 |  |  |         do { | 
 |  |  |             write = siemensS7Net.Write("DB100.600", staProtocol.isTailSupportFlag() ? 1 : 0);    // 0 不是尾桶,1 是尾桶 | 
 |  |  |             Thread.sleep(200); | 
 |  |  |             if(write.IsSuccess){ | 
 |  |  |                 break; | 
 |  |  |             } | 
 |  |  |             else { | 
 |  |  |                 writeCount++; | 
 |  |  |                 log.error("写入尾桶命令失败。输送线plc编号={},是否尾桶={},写入次数={}", slave.getId(), staProtocol.isTailSupportFlag(), writeCount); | 
 |  |  |             } | 
 |  |  |         }while (writeCount<5); | 
 |  |  |  | 
 |  |  |         if (!write.IsSuccess) { | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入尾桶命令数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), staProtocol.isTailSupportFlag())); | 
 |  |  |             News.error("SiemensDevp"+" - 4"+" - 写入尾桶命令数据失败。输送线plc编号={},站点数据={}", slave.getId(), staProtocol.isTailSupportFlag()); | 
 |  |  |         } else { | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 写入尾桶命令下发 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), staProtocol.isTailSupportFlag())); | 
 |  |  |             News.info("SiemensDevp"+" - 5"+" - 写入尾桶命令下发 [id:{}] >>>>> 命令下发: {}",  slave.getId(), staProtocol.isTailSupportFlag()); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 入罐装线前wcs写桶型信息 | 
 |  |  |      */ | 
 |  |  |     private void writeGzx(StaProtocol staProtocol) throws InterruptedException { | 
 |  |  |         if (null == staProtocol) { | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |         short[] common = new short[3]; | 
 |  |  |         common[0] = Short.parseShort(staProtocol.getBucketType()); | 
 |  |  |         common[1] = (short) staProtocol.getBucketCount(); | 
 |  |  |         common[2] = staProtocol.getWorkNo().shortValue(); | 
 |  |  |         OperateResult write; | 
 |  |  |         //任务下发次数 | 
 |  |  |         int writeCount = 0; | 
 |  |  |         do { | 
 |  |  |             write = siemensS7Net.Write("DB100.0", common); | 
 |  |  |             Thread.sleep(200); | 
 |  |  |             OperateResultExOne<byte[]> read = siemensS7Net.Read("DB100.0", (short) 6); | 
 |  |  |             if(write.IsSuccess && read.IsSuccess){ | 
 |  |  |                 short bucketType = siemensS7Net.getByteTransform().TransInt16(read.Content, 0); | 
 |  |  |                 short bucketCount = siemensS7Net.getByteTransform().TransInt16(read.Content, 2); | 
 |  |  |                 short workNo = siemensS7Net.getByteTransform().TransInt16(read.Content, 4); | 
 |  |  |                 if ( workNo != common[2] || bucketCount != common[1] || bucketType != common[0]) { | 
 |  |  |                     writeCount++; | 
 |  |  |                     log.error("给罐装线写入桶型信息成功,但回读失败:写入任务号:{},回读任务号:{},输送线plc编号={},写入次数={}", Arrays.toString(common), bucketType +"-" + bucketCount + "-" + workNo, slave.getId(), writeCount); | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 log.info("给罐装线写入桶型信息成功,回读成功:任务号:{},回读任务号:{},输送线plc编号={},写入次数={}",staProtocol.getWorkNo().shortValue(), Arrays.toString(common), slave.getId(), writeCount); | 
 |  |  |                 break; | 
 |  |  |             } | 
 |  |  |             else { | 
 |  |  |                 writeCount++; | 
 |  |  |                 log.error("给罐装线写入桶型信息失败。输送线plc编号={},是否尾桶={},写入次数={}", slave.getId(), staProtocol.isTailSupportFlag(), writeCount); | 
 |  |  |             } | 
 |  |  |         }while (writeCount<5); | 
 |  |  |  | 
 |  |  |         if (!write.IsSuccess) { | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入尾桶命令数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), staProtocol.isTailSupportFlag())); | 
 |  |  |             News.error("SiemensDevp"+" - 4"+" - 给罐装线写入桶型信息失败。输送线plc编号={},站点数据={}", slave.getId(), staProtocol.isTailSupportFlag()); | 
 |  |  |         } else { | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 给罐装线写入桶型信息命令下发成功 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), staProtocol.isTailSupportFlag())); | 
 |  |  |             News.info("SiemensDevp"+" - 5"+" - 给罐装线写入桶型信息命令下发成功 [id:{}] >>>>> 命令下发: {}",  slave.getId(), staProtocol.getBucketType()); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 给罐装线写入可出信号 | 
 |  |  |      */ | 
 |  |  |     private void writeGzxkc(StaProtocol staProtocol) throws InterruptedException { | 
 |  |  |         if (null == staProtocol) { | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |         short[] common = new short[1]; | 
 |  |  |         common[0] = (short) staProtocol.getPlaceableFlag(); | 
 |  |  |  | 
 |  |  |         OperateResult write; | 
 |  |  |         //任务下发次数 | 
 |  |  |         int writeCount = 0; | 
 |  |  |         do { | 
 |  |  |             write = siemensS7Net.Write("DB100.6", common); | 
 |  |  |             Thread.sleep(200); | 
 |  |  |             OperateResultExOne<byte[]> read = siemensS7Net.Read("DB100.6", (short) 2); | 
 |  |  |             if(write.IsSuccess && read.IsSuccess){ | 
 |  |  |                 short i = siemensS7Net.getByteTransform().TransInt16(read.Content, 0); | 
 |  |  |                 if ( i != 1) { | 
 |  |  |                     writeCount++; | 
 |  |  |                     log.error("给罐装线写入可出信号成功,但回读失败:读取值:{},输送线plc编号={},写入次数={}", i, slave.getId(), writeCount); | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 break; | 
 |  |  |             } | 
 |  |  |             else { | 
 |  |  |                 writeCount++; | 
 |  |  |                 log.error("给罐装线写入可出信号:{}失败。输送线plc编号={},写入次数={}", common[0], slave.getId(), writeCount); | 
 |  |  |             } | 
 |  |  |         }while (writeCount<5); | 
 |  |  |  | 
 |  |  |         if (!write.IsSuccess) { | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】给罐装线写入可出信号失败。输送线plc编号={1},站点数据={2}", slave.getId(), staProtocol.getPlaceableFlag())); | 
 |  |  |             News.error("SiemensDevp"+" - 4"+" - 给罐装线写入可出信号失败。输送线plc编号={},站点数据={}", slave.getId(), staProtocol.getPlaceableFlag()); | 
 |  |  |         } else { | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 给罐装线写入可出信号命令下发成功 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), staProtocol.getPlaceableFlag())); | 
 |  |  |             News.info("SiemensDevp"+" - 5"+" - 给罐装线写入可出信号命令下发成功 [id:{}] >>>>> 命令下发: {}",  slave.getId(), staProtocol.getPlaceableFlag()); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 给罐装线写罐装数量 | 
 |  |  |      */ | 
 |  |  |     private void writeGzsl(StaProtocol staProtocol) throws InterruptedException { | 
 |  |  |         if (null == staProtocol) { | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |         short[] common = new short[1]; | 
 |  |  |         common[0] = (short) staProtocol.getWantBucketCount(); | 
 |  |  |  | 
 |  |  |         OperateResult write; | 
 |  |  |         //任务下发次数 | 
 |  |  |         int writeCount = 0; | 
 |  |  |         do { | 
 |  |  |             write = siemensS7Net.Write("DB100.8", common); | 
 |  |  |             Thread.sleep(200); | 
 |  |  |             OperateResultExOne<byte[]> read = siemensS7Net.Read("DB100.8", (short) 2); | 
 |  |  |             if(write.IsSuccess && read.IsSuccess){ | 
 |  |  |                 short i = siemensS7Net.getByteTransform().TransInt16(read.Content, 0); | 
 |  |  |                 if ( i != common[0]) { | 
 |  |  |                     writeCount++; | 
 |  |  |                     log.error("给罐装线写罐装数量成功,但回读失败:读取值:{},输送线plc编号={},写入次数={}", i, slave.getId(), writeCount); | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 break; | 
 |  |  |             } | 
 |  |  |             else { | 
 |  |  |                 writeCount++; | 
 |  |  |                 log.error("给罐装线写罐装数量:{}失败。输送线plc编号={},写入次数={}", common[0], slave.getId(), writeCount); | 
 |  |  |             } | 
 |  |  |         }while (writeCount<5); | 
 |  |  |  | 
 |  |  |         if (!write.IsSuccess) { | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】给给罐装线写罐装数量失败。输送线plc编号={1},站点数据={2}", slave.getId(), staProtocol.getWantBucketCount())); | 
 |  |  |             News.error("给罐装线写罐装数量失败。输送线plc编号={},站点数据={}", slave.getId(), staProtocol.getWantBucketCount()); | 
 |  |  |         } else { | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 给罐装线写罐装数量命令下发成功 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), staProtocol.getWantBucketCount())); | 
 |  |  |             News.info("给罐装线写罐装数量号命令下发成功 [id:{}] >>>>> 命令下发: {}",  slave.getId(), staProtocol.getWantBucketCount()); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |         siemensS7Net.ConnectClose(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public static void main(String[] args) { | 
 |  |  |         System.out.println(staNos1.indexOf(129)); | 
 |  |  |         System.out.println(staNos1.size()); | 
 |  |  |         for (int i = 0; i<staNos1.size(); i++) { | 
 |  |  | //            System.out.println(i*2); | 
 |  |  | //            System.out.println(i*2 + 200); | 
 |  |  | //            System.out.println(i); | 
 |  |  |         } | 
 |  |  |         int index = staNos1.indexOf(128); | 
 |  |  |         System.out.println(index*2); | 
 |  |  |         System.out.println(index*2 + 200); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | //    public static void main(String[] args) throws Exception { | 
 |  |  | //        DevpSlave slave = new DevpSlave(); | 
 |  |  | //        slave.setIp("192.168.2.125"); | 
 |  |  | //        SiemensDevpThread devpThread = new SiemensDevpThread(slave); | 
 |  |  | //        devpThread.connect(); | 
 |  |  | //        devpThread.read(); | 
 |  |  |     public static void main(String[] args) throws Exception { | 
 |  |  |         DevpSlave slave = new DevpSlave(); | 
 |  |  |         slave.setIp("10.10.10.18"); | 
 |  |  |         SiemensDevpThread devpThread = new SiemensDevpThread(slave); | 
 |  |  |         devpThread.connect(); | 
 |  |  |         devpThread.read(); | 
 |  |  | //        // 写 | 
 |  |  | //        StaProtocol staProtocol = devpThread.getStation().get(1); | 
 |  |  | //        staProtocol.setWorkNo((short) 232); | 
 |  |  | 
 |  |  | //        // 读 | 
 |  |  | //        devpThread.read(); | 
 |  |  | //        System.out.println(JSON.toJSONString(devpThread.station)); | 
 |  |  | // | 
 |  |  | //    } | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } |