| | |
| | | private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>(); |
| | | private short heartBeatVal = 1; |
| | | 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(1001);add(1002);add(1003);add(1004); |
| | | add(1001); |
| | | add(1002); |
| | | add(1003); |
| | | add(1004); |
| | | add(1005); |
| | | add(1010); |
| | | add(1006); |
| | | add(1007); |
| | | add(1008); |
| | | add(1009); |
| | | add(1011); |
| | | add(1012); |
| | | add(1013); |
| | | add(1014); |
| | | add(1015); |
| | | add(1016); |
| | | add(1017); |
| | | add(1018); |
| | | add(1019); |
| | | add(1020); |
| | | |
| | | |
| | | }}; |
| | | /*public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{ |
| | | 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); |
| | | add(224);add(225);add(226);add(227); |
| | | add(228);add(229);add(230);add(231); |
| | | add(232);add(233);add(234);add(235); |
| | | public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{ |
| | | add(2001); |
| | | add(2002); |
| | | add(2003); |
| | | add(2004); |
| | | add(2005); |
| | | add(2006); |
| | | add(2007); |
| | | add(2008); |
| | | add(2009); |
| | | add(2010); |
| | | add(2011); |
| | | add(2012); |
| | | add(2013); |
| | | add(2014); |
| | | add(2015); |
| | | add(2016); |
| | | add(2017); |
| | | add(2018); |
| | | add(2019); |
| | | |
| | | }}; |
| | | public static final ArrayList<Integer> staNos3 = new ArrayList<Integer>() {{ |
| | | add(300);add(301);add(302);add(303); |
| | | add(304);add(305);add(306);add(307); |
| | | add(1051); |
| | | add(1052); |
| | | add(1053); |
| | | add(1054); |
| | | add(1055); |
| | | add(1056); |
| | | add(1057); |
| | | add(1058); |
| | | }}; |
| | | public static final ArrayList<Integer> staNos4 = new ArrayList<Integer>() {{ |
| | | add(400);add(401);add(402);add(403); |
| | | add(404);add(405);add(406);add(407); |
| | | }};*/ |
| | | add(2051); |
| | | add(2052); |
| | | add(2053); |
| | | add(2054); |
| | | add(2055); |
| | | add(2056); |
| | | add(2057); |
| | | add(2058); |
| | | |
| | | }}; |
| | | |
| | | /** |
| | | * 条码数量 |
| | |
| | | * 4.出库模式 |
| | | */ |
| | | public IoModeType ioModeOf2F = IoModeType.NONE; |
| | | |
| | | // public IoModeType ioMode = IoModeType.NONE; |
| | | private ArrayList<Integer> getStaNo() { |
| | | switch (slave.getId()) { |
| | | case 1: |
| | | return staNos1; |
| | | /*case 2: |
| | | case 2: |
| | | return staNos2; |
| | | case 3: |
| | | return staNos3; |
| | | case 4: |
| | | return staNos4;*/ |
| | | return staNos4; |
| | | default: |
| | | throw new CoolException("服务器异常"); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // OperateResultExOne<byte[]> resultAgvAndPlc = siemensS7Net.Read("DB102.0", (short) 30); |
| | | // if (resultAgvAndPlc.IsSuccess) { |
| | | // for (int i = 0; i < staNoSize; i++) { |
| | | // int sign =(i+2)/2-1; |
| | | // if ((i+2)%2!=0){ |
| | | // Integer siteId = staNos.get(i); // 站点编号 |
| | | // StaProtocol staProtocol = station.get(siteId); |
| | | // if (null == staProtocol) { |
| | | // staProtocol = new StaProtocol(); |
| | | // staProtocol.setSiteId(siteId); |
| | | // station.put(siteId, staProtocol); |
| | | // } |
| | | // staProtocol.setAgvStartPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6+4)); // 允许取货 |
| | | // staProtocol.setAgvStartPlace((short)0); // 允许放货 |
| | | // continue; |
| | | // } |
| | | // Integer siteId = staNos.get(i); // 站点编号 |
| | | // StaProtocol staProtocol = station.get(siteId); |
| | | // if (null == staProtocol) { |
| | | // staProtocol = new StaProtocol(); |
| | | // staProtocol.setSiteId(siteId); |
| | | // station.put(siteId, staProtocol); |
| | | // } |
| | | // staProtocol.setAgvStartPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6)); // 允许取货 |
| | | // staProtocol.setAgvStartPlace(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6 + 2)); // 允许放货 |
| | | // } |
| | | // } |
| | | |
| | | // OperateResultExOne<byte[]> resultAgvAndPlcOk = siemensS7Net.Read("DB132.0", (short) 30); |
| | | // if (resultAgvAndPlcOk.IsSuccess) { |
| | | // for (int i = 0; i < staNoSize; i++) { |
| | | // int sign =(i+2)/2-1; |
| | | // if ((i+2)%2!=0){ |
| | | // Integer siteId = staNos.get(i); // 站点编号 |
| | | // StaProtocol staProtocol = station.get(siteId); |
| | | // if (null == staProtocol) { |
| | | // staProtocol = new StaProtocol(); |
| | | // staProtocol.setSiteId(siteId); |
| | | // station.put(siteId, staProtocol); |
| | | // } |
| | | // staProtocol.setAgvTargetPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlcOk.Content, sign*6+4)); // 允许取货 |
| | | // staProtocol.setAgvTargetPlace((short)0); // 允许放货 |
| | | // continue; |
| | | // } |
| | | // Integer siteId = staNos.get(i); // 站点编号 |
| | | // StaProtocol staProtocol = station.get(siteId); |
| | | // if (null == staProtocol) { |
| | | // staProtocol = new StaProtocol(); |
| | | // staProtocol.setSiteId(siteId); |
| | | // station.put(siteId, staProtocol); |
| | | // } |
| | | // try{ |
| | | // staProtocol.setAgvTargetPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlcOk.Content, sign*6)); // 取货完成 |
| | | // if (staProtocol.getAgvTargetPick()!=0){ |
| | | // System.out.println(staProtocol.getAgvTargetPick()); |
| | | // } |
| | | // staProtocol.setAgvTargetPlace(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlcOk.Content, sign*6 + 2)); // 放货完成 |
| | | // if (staProtocol.getAgvTargetPlace()!=0){ |
| | | // System.out.println(staProtocol.getAgvTargetPlace()); |
| | | // } |
| | | // }catch (Exception e){ |
| | | // log.error(""+e); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | |
| | | if (slave.getId() == 1) { |
| | | //条码 |
| | | //Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.848.0", (short) 8); |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.840.0", (short) 8); |
| | | if (result2.IsSuccess) { |
| | | for (int i = 0; i < 1; i++) { |
| | | String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 8, 8, "UTF-8"); |
| | |
| | | } |
| | | |
| | | //外形检测 |
| | | OperateResultExOne<byte[]> resultErr1 = siemensS7Net.Read("DB101.810.0", (short) (barcodeSize*1)); |
| | | StaProtocol staProtocol1 = station.get(116); |
| | | OperateResultExOne<byte[]> resultErr1 = siemensS7Net.Read("DB101.802.0", (short) (barcodeSize * 1)); |
| | | if (resultErr1.IsSuccess) { |
| | | int sta = 0; |
| | | switch (slave.getId()) { |
| | | case 1: |
| | | sta = 1014; |
| | | break; |
| | | case 2: |
| | | sta = 2007; |
| | | break; |
| | | case 3: |
| | | sta = 1052; |
| | | break; |
| | | case 4: |
| | | sta = 2056; |
| | | break; |
| | | } |
| | | StaProtocol staProtocol1 = station.get(sta); |
| | | boolean[] status1 = siemensS7Net.getByteTransform().TransBool(resultErr1.Content, 0, 1); |
| | | staProtocol1.setFrontErr(status1[0]); |
| | | staProtocol1.setBackErr(status1[1]); |
| | |
| | | staProtocol1.setRightErr(status1[4]); |
| | | staProtocol1.setWeightErr(status1[5]); |
| | | staProtocol1.setBarcodeErr(status1[6]); |
| | | } |
| | | |
| | | |
| | | OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.922.0", (short) (staNoSize * 4)); |
| | | if (resultErr.IsSuccess) { |
| | |
| | | staProtocol.setUpcontactErr(status[7]); |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | // } |
| | | |
| | | if (result.IsSuccess ) { |
| | | |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | | // 根据实时信息更新数据库 |
| | |
| | | |
| | | |
| | | } |
| | | |
| | | private void write(StaProtocol staProtocol) throws InterruptedException { |
| | | if (staProtocol == null) { |
| | | return; |
| | |
| | | boolean writeFlag = false; // 任务下发成功标记 |
| | | String plcAddressWorkNo = "DB100." + index * 6; |
| | | String plcAddressStaNo = "DB100." + (index * 6 + 4); |
| | | |
| | | Thread.sleep(100); |
| | | while (writeCount < 5) { |
| | | // **读取当前PLC状态,避免不必要的写入** |
| | | OperateResultExOne<byte[]> readResult = siemensS7Net.Read(plcAddressWorkNo, (short) 6); |