| | |
| | | }}; |
| | | public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{ |
| | | add(300);add(301);add(302);add(303);add(304); |
| | | add(311);add(312);add(313);add(314);add(315); |
| | | }}; |
| | | |
| | | |
| | | |
| | | public static final ArrayList<Integer> barcode1 = new ArrayList<Integer>() {{ |
| | | add(1); add(2); |
| | |
| | | |
| | | public static final ArrayList<Integer> barcode2 = new ArrayList<Integer>() {{ |
| | | add(3); |
| | | }}; |
| | | |
| | | public static final ArrayList<Integer> barcode3 = new ArrayList<Integer>() {{ |
| | | add(4); |
| | | }}; |
| | | |
| | | private Integer count=0; |
| | |
| | | return barcode1; |
| | | case 2: |
| | | return barcode2; |
| | | case 3: |
| | | return barcode3; |
| | | default: |
| | | throw new CoolException("获取条码扫描器失败!"); |
| | | } |
| | |
| | | } |
| | | } else { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】读取输送线plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | log.error("读取输送线plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort()); |
| | | // log.error("读取输送线plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | |
| | | //条码扫描器 |
| | |
| | | } |
| | | } else { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】读取输送线plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | log.error("读取输送线plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort()); |
| | | // log.error("读取输送线plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | |
| | | //外形检测 |
| | | OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.42", (short) 8); |
| | | if (resultErr.IsSuccess) { |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, 0, 1); |
| | | StaProtocol staProtocol = station.get(303); |
| | | StaProtocol staProtocol = station.get(304); |
| | | staProtocol.setFrontErr(status[0]); |
| | | staProtocol.setBackErr(status[1]); |
| | | staProtocol.setHighErr(status[2]); |
| | |
| | | } |
| | | // 根据实时信息更新数据库 |
| | | try { |
| | | if (!station.isEmpty()) { |
| | | List<BasDevp> basDevps = new ArrayList<>(); |
| | | for (Integer siteId : staNos) { |
| | | StaProtocol staProtocol = station.get(siteId); |
| | |
| | | BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); |
| | | if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) { |
| | | throw new Exception("更新数据库数据失败"); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB100." + index*6, (short)4); |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> readResult1 = siemensS7Net.Read("DB100." + index*6+4, (short)2); |
| | | OperateResultExOne<byte[]> readResult1 = siemensS7Net.Read("DB100." + (index*6+4), (short)2); |
| | | //OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB1000." + index*4, (short)4); |
| | | if(readResult.IsSuccess && readResult1.IsSuccess){ |
| | | short workNo = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 0); |
| | | short staNo = siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 2); |
| | | if(staProtocol.getWorkNo().equals(workNo) && staProtocol.getStaNo().equals(staNo)){ |
| | | int workNo = siemensS7Net.getByteTransform().TransInt32(readResult.Content, 0); |
| | | short staNo = siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 0); |
| | | if(staProtocol.getWorkNo().equals((short)workNo) && staProtocol.getStaNo().equals(staNo)){ |
| | | //任务命令写入成功 |
| | | writeFlag = true; |
| | | log.info("写入输送线命令后返回成功,并且回读成功。输送线plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | |
| | | log.error("写入输送线命令尝试5次失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol)); |
| | | |
| | | //重新添加数据到任务队列 |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, slave.getId(), new Task(2, staProtocol)); |
| | | // boolean result = MessageQueue.offer(SlaveType.Devp, slave.getId(), new Task(2, staProtocol)); |
| | | read();//读取1次设备状态 |
| | | return; |
| | | } else { |