| | |
| | | // |
| | | // }}; |
| | | 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); |
| | | }}; |
| | | |
| | | 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(101);add(102); |
| | | }}; |
| | | |
| | | |
| | |
| | | /** |
| | | * 条码数量 |
| | | */ |
| | | private int barcodeSize = 6; |
| | | private int barcodeSize = 1; |
| | | |
| | | /** |
| | | * 入出库模式 |
| | |
| | | switch (slave.getId()) { |
| | | case 1: |
| | | return staNos1; |
| | | case 2: |
| | | return staNos2; |
| | | default: |
| | | throw new CoolException("服务器异常"); |
| | | } |
| | |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setSiteId(siteId); |
| | | staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*2)); // 工作号 |
| | | |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result4.Content, i*2)); // 目标站 |
| | |
| | | // } |
| | | //条码扫描器 |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.200",(short)(barcodeSize/2*8)); |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.200",(short)(barcodeSize*8)); |
| | | if (result2.IsSuccess) { |
| | | if (slave.getId()==1){ |
| | | for (int i = 0; i < barcodeSize/2; 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)){ |
| | | 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)){ |
| | | // && !Cools.isEmpty(barcode) && Cools.isEmpty(barcodeThread.getBarcode())) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | }else if (slave.getId()==2){ |
| | | for (int i = barcodeSize/2; i < barcodeSize; i++) { |
| | | String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,(i-barcodeSize/2)*8,8, "UTF-8"); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)){ |
| | | // && !Cools.isEmpty(barcode) && Cools.isEmpty(barcodeThread.getBarcode())) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | Thread.sleep(200); |
| | |
| | | staProtocol.setStamp(staProtocol.getStamp()+1); |
| | | } |
| | | |
| | | // //20230110,日志打印,确认收到入库站可入信号时,对应条码数据是否已有 |
| | | // if ((siteId==101 || siteId==109 || siteId==117 || siteId==201 || siteId==207 || siteId==213) |
| | | // && staProtocol.isInEnable()){ |
| | | // Integer barcodeId = 0; |
| | | // switch (siteId){ |
| | | // case 101: |
| | | // barcodeId=1; |
| | | // break; |
| | | // case 109: |
| | | // barcodeId=2; |
| | | // break; |
| | | // case 117: |
| | | // barcodeId=3; |
| | | // break; |
| | | // case 201: |
| | | // barcodeId=4; |
| | | // break; |
| | | // case 207: |
| | | // barcodeId=5; |
| | | // break; |
| | | // case 213: |
| | | // barcodeId=6; |
| | | // break; |
| | | // } |
| | | // BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId); |
| | | // if(barcodeThread!=null){ |
| | | // //lfd入库印记 当stamp>=2时才入库 |
| | | // staProtocol.setStamp(staProtocol.getStamp()+1); |
| | | // News.info("{}站有可入信号时,条码值为{}", siteId, barcodeThread.getBarcode()); |
| | | // if(Cools.isEmpty(barcodeThread.getBarcode())){ |
| | | // staProtocol.setInEnable(false);//条码数据为空时,先清一次内存的站点可入信号,等待下一次获取可入信号 |
| | | // } |
| | | // } |
| | | // } |
| | | } |
| | | } |
| | | |
| | | // //RGV小车 |
| | | // Thread.sleep(200); |
| | | // OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB100.160",(short)2); |
| | | // if (result3.IsSuccess) { |
| | | // Integer siteId = 16; |
| | | // StaProtocol staProtocol = station.get(siteId); |
| | | // if (null == staProtocol) { |
| | | // staProtocol = new StaProtocol(); |
| | | // staProtocol.setSiteId(siteId); |
| | | // station.put(siteId, staProtocol); |
| | | // } |
| | | // staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result3.Content, 0))); |
| | | // } |
| | | |
| | | |
| | | |
| | | if (result.IsSuccess && result1.IsSuccess) { |
| | | |
| | |
| | | |
| | | } else { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】读取输送线plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | // log.error("读取输送线plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | } |
| | | } |
| | | |
| | |
| | | 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(); |
| | | // // 写 |
| | | // StaProtocol staProtocol = devpThread.getStation().get(1); |
| | | // staProtocol.setWorkNo((short) 232); |
| | | // staProtocol.setStaNo((short) 6); |
| | | // staProtocol.setAutoing(true); |
| | | // staProtocol.setEmptyMk(true); |
| | | // staProtocol.setInEnable(true); |
| | | // devpThread.write(staProtocol); |
| | | // System.out.println("----------------------------------------"); |
| | | // // 读 |
| | | // devpThread.read(); |
| | | // System.out.println(JSON.toJSONString(devpThread.station)); |
| | | // |
| | | // } |
| | | |
| | | } |