| | |
| | | private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>(); |
| | | private short heartBeatVal = 1; |
| | | private int barcodeSize = 10; |
| | | |
| | | public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{ |
| | | add(100);add(101); |
| | | add(102);add(103); |
| | | add(104);add(105); |
| | | add(200);add(201); |
| | | add(202);add(203); |
| | | add(204);add(205); |
| | | add(300);add(301); |
| | | add(340);add(341); |
| | | add(345);add(346); |
| | | add(303);add(317); |
| | | add(325);add(331); |
| | | add(333);add(339); |
| | | add(309);add(312); |
| | | }}; |
| | | |
| | | //高低信号站点 |
| | | public static final ArrayList<Integer> locType1StaNos = new ArrayList<Integer>() {{ |
| | | add(100);add(103); |
| | | add(105);add(200); |
| | | add(203);add(205); |
| | | add(300);add(341); |
| | | add(346); |
| | | }}; |
| | | |
| | | //出入库模式 |
| | | public static final ArrayList<Integer> outInModelStaNos = new ArrayList<Integer>() {{ |
| | | add(100);add(103); |
| | | add(105);add(200); |
| | | add(203);add(205); |
| | | add(341);add(346); |
| | | }}; |
| | | |
| | | //出入库站点检测报警信息 |
| | | public static final ArrayList<Integer> outInAlarmStaNos = new ArrayList<Integer>(){{ |
| | | add(101);add(102);add(104); |
| | | add(201);add(202);add(204); |
| | | add(340);add(345); |
| | | }}; |
| | | |
| | | public boolean charge0; |
| | | public boolean charge1; |
| | | |
| | | public SiemensDevpThread(DevpSlave slave) { |
| | | this.slave = slave; |
| | |
| | | } |
| | | // 心跳 |
| | | // heartbeat(); |
| | | Thread.sleep(400); |
| | | Thread.sleep(100); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | 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())); |
| | | News.error("输送线plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | siemensS7Net.ConnectClose(); |
| | | // siemensS7Net.ConnectClose(); |
| | | return result; |
| | | } |
| | | |
| | |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*4+2)); // 目标站 |
| | | } |
| | | } |
| | | |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB1001.0", (short) (staNos.size()*2)); |
| | | if (result1.IsSuccess) { |
| | |
| | | } |
| | | } |
| | | |
| | | //读条码 |
| | | Thread.sleep(100); |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB1000.200", (short) 98); |
| | | if (result2.IsSuccess) { |
| | | for (int i = 0; i < barcodeSize; i++) { |
| | | if (i >= 10) { |
| | | continue; |
| | | } |
| | | |
| | | String barcode = null; |
| | | if (i == 8) { |
| | | barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,13, "UTF-8"); |
| | | } else if (i == 9) { |
| | | barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8 + 6,13, "UTF-8"); |
| | | } else { |
| | | 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)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //读高低信号 |
| | | Thread.sleep(100); |
| | | OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB1000.300", (short) (locType1StaNos.size()*2)); |
| | | if (result3.IsSuccess) { |
| | | for (int i = 0; i < locType1StaNos.size(); i++) { |
| | | Integer siteId = locType1StaNos.get(i); // 站点编号 |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | staProtocol.setLocType1(siemensS7Net.getByteTransform().TransInt16(result3.Content, i * 2));//读取高低信号 |
| | | } |
| | | } |
| | | |
| | | //读出入库模式 |
| | | Thread.sleep(100); |
| | | OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB1002.0", (short) (outInModelStaNos.size()*2)); |
| | | if (result4.IsSuccess) { |
| | | for (int i = 0; i < outInModelStaNos.size(); i++) { |
| | | Integer siteId = outInModelStaNos.get(i); // 站点编号 |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | staProtocol.setOutInModel(siemensS7Net.getByteTransform().TransInt16(result4.Content, i * 2));//读取出入库模式 |
| | | } |
| | | } |
| | | |
| | | //出入库站点检测报警信息 |
| | | Thread.sleep(100); |
| | | for (Integer staNo : outInAlarmStaNos) { |
| | | OperateResultExOne<byte[]> result5 = siemensS7Net.Read("DB" + staNo + ".20.0", (short) 2); |
| | | if (result5.IsSuccess) { |
| | | if (staNo == 101 || staNo == 201) { |
| | | staNo--; |
| | | }else { |
| | | staNo++; |
| | | } |
| | | StaProtocol staProtocol = station.get(staNo); |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result5.Content, 0, 2); |
| | | staProtocol.setBarcodeErr(status[4]);//扫码失败 |
| | | staProtocol.setFrontErr(status[8]);//前超限 |
| | | staProtocol.setBackErr(status[9]);//后超限 |
| | | staProtocol.setLeftErr(status[10]);//左超限 |
| | | staProtocol.setRightErr(status[11]);//右超限 |
| | | staProtocol.setHighErr(status[12]);//超高 |
| | | staProtocol.setWeightErr(status[13]);//超重 |
| | | } |
| | | } |
| | | |
| | | if (result.IsSuccess && result1.IsSuccess) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | |
| | | for (Integer siteId : staNos) { |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | basDevps.add(staProtocol.toSqlModel()); |
| | | // log.info("输送线信号,{}", JSON.toJSONString(staProtocol)); |
| | | } |
| | | BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); |
| | | if (!basDevpService.updateBatchById(basDevps)) { |
| | |
| | | while(writeCount < 1){ |
| | | writeResult = siemensS7Net.Write("DB1000." + index*4, array); // 工作号、目标站 |
| | | if(writeResult.IsSuccess){ |
| | | Thread.sleep(200); |
| | | Thread.sleep(500); |
| | | OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB1000." + index*4, (short)4); |
| | | if(readResult.IsSuccess){ |
| | | short workNo = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 0); |
| | |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线命令尝试5次失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol))); |
| | | 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 { |