| | |
| | | write((StaProtocol)task.getData()); |
| | | read(); |
| | | break; |
| | | // 写数据 ID+目标站 |
| | | case 4: |
| | | writeAgvOk((StaProtocol)task.getData()); |
| | | read(); |
| | | break; |
| | | /* case 3: |
| | | write2((StaProtocol)task.getData()); |
| | | read(); |
| | | break;*/ |
| | | default: |
| | | break; |
| | | } |
| | |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setWorkNo((short) 0); // ID |
| | | staProtocol.setWorkNo(0); // ID |
| | | staProtocol.setAutoing(false); // 自动 |
| | | staProtocol.setLoading(false); // 有物 |
| | | staProtocol.setInEnable(false); // 可入 |
| | | staProtocol.setOutEnable(false); // 可出 |
| | | staProtocol.setEmptyMk(false); // 空板信号 |
| | | staProtocol.setStaNo((short) 0); // 目标站 |
| | | staProtocol.setStaNo(0); // 目标站 |
| | | |
| | | if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { |
| | | staProtocol.setPakMk(true); |
| | |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setWorkNo((short)siemensS7Net.getByteTransform().TransInt32(result.Content, i*8)); // 工作号 |
| | | staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result.Content, i*8)); // 工作号 |
| | | |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*8 + 4)); // 目标站 |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt32(result.Content, i*8 + 4)); // 目标站 |
| | | |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, i*8 + 6, 2); |
| | | staProtocol.setAutoing(status[0]); // 自动 |
| | |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setAgvStartPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6+4)); // 允许取货 |
| | | staProtocol.setAgvStartPlace((short)0); // 允许放货 |
| | | // staProtocol.setAgvStartPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6+4)); // 允许取货 |
| | | // staProtocol.setAgvStartPlace((short)0); // 允许放货 |
| | | continue; |
| | | } |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | |
| | | 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)); // 允许放货 |
| | | // staProtocol.setAgvStartPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6)); // 允许取货 |
| | | // staProtocol.setAgvStartPlace(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6 + 2)); // 允许放货 |
| | | } |
| | | } |
| | | |
| | |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setAgvTargetPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlcOk.Content, sign*6+4)); // 允许取货 |
| | | staProtocol.setAgvTargetPlace((short)0); // 允许放货 |
| | | // staProtocol.setAgvTargetPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlcOk.Content, sign*6+4)); // 允许取货 |
| | | // staProtocol.setAgvTargetPlace((short)0); // 允许放货 |
| | | continue; |
| | | } |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | |
| | | 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); |
| | | } |
| | | // 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); |
| | | // } |
| | | } |
| | | } |
| | | |
| | |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i * 4, 1); |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | staProtocol.setBreakerErr(status[0]); |
| | | staProtocol.setInfraredErr(status[1]); |
| | | staProtocol.setOutTimeErr(status[2]); |
| | | staProtocol.setSeizeSeatErr(status[3]); |
| | | staProtocol.setWrkYgoodsN(status[4]); |
| | | staProtocol.setInverterErr(status[5]); |
| | | staProtocol.setContactErr(status[6]); |
| | | staProtocol.setUpcontactErr(status[7]); |
| | | // staProtocol.setBreakerErr(status[0]); |
| | | // staProtocol.setInfraredErr(status[1]); |
| | | // staProtocol.setOutTimeErr(status[2]); |
| | | // staProtocol.setSeizeSeatErr(status[3]); |
| | | // staProtocol.setWrkYgoodsN(status[4]); |
| | | // staProtocol.setInverterErr(status[5]); |
| | | // staProtocol.setContactErr(status[6]); |
| | | // staProtocol.setUpcontactErr(status[7]); |
| | | |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 写入 ID+目标站 =====> 单站点写入 |
| | | */ |
| | | private void writeAgvOk(StaProtocol staProtocol) throws InterruptedException { |
| | | if (null == staProtocol) { |
| | | return; |
| | | } |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | int index = staNos.indexOf(staProtocol.getSiteId()); |
| | | if (staProtocol.getAgvTypeSign()==0 || staProtocol.getAgvTypeSign()==2 ){ //0取货 |
| | | switch (staProtocol.getSiteId()){ |
| | | case 100: |
| | | index=32; |
| | | break; |
| | | case 101: |
| | | index=34; |
| | | break; |
| | | case 102: |
| | | index=38; |
| | | break; |
| | | case 103: |
| | | index=40; |
| | | break; |
| | | case 104: |
| | | index=44; |
| | | break; |
| | | case 105: |
| | | index=46; |
| | | break; |
| | | case 106: |
| | | index=50; |
| | | break; |
| | | case 107: |
| | | index=52; |
| | | break; |
| | | default: |
| | | return; |
| | | } |
| | | }else { |
| | | switch (staProtocol.getSiteId()){ |
| | | case 100: |
| | | index=30; |
| | | break; |
| | | case 102: |
| | | index=36; |
| | | break; |
| | | case 104: |
| | | index=42; |
| | | break; |
| | | case 106: |
| | | index=48; |
| | | break; |
| | | default: |
| | | return; |
| | | } |
| | | } |
| | | |
| | | OperateResult write = null; |
| | | //任务下发次数 |
| | | int writeCount = 0; |
| | | do { |
| | | short textWrite = 1;// 任务完成 |
| | | if (staProtocol.getAgvTypeSign()>1){ |
| | | textWrite = 0;// 任务复位 |
| | | } |
| | | write = siemensS7Net.Write("DB102." + index, textWrite); |
| | | if(write.IsSuccess){ |
| | | writeCount=6; |
| | | }else { |
| | | writeCount++; |
| | | log.error("写入输送线取放货完成命令后读取失败。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | } |
| | | }while (writeCount<5); |
| | | |
| | | if (!write.IsSuccess) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol))); |
| | | log.error("写入输送线取放货完成站点数据失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol)); |
| | | } else { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol))); |
| | | log.info("输送线取放货完成命令下发码垛完成 给输送线写任务完成 [id:{}] >>>>> 命令下发: {}", slave.getId(), JSON.toJSON(staProtocol)); |
| | | } |
| | | |
| | | |
| | | } |
| | | private void write(StaProtocol staProtocol) throws InterruptedException { |
| | | if (null == staProtocol) { |
| | | return; |
| | |
| | | // } |
| | | } |
| | | |
| | | |
| | | } |
| | | private void write2(StaProtocol staProtocol) throws InterruptedException { |
| | | if (null == staProtocol) { |
| | | return; |
| | | } |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | |
| | | int index = staNos.indexOf(staProtocol.getSiteId()); |
| | | short[] array = new short[2]; |
| | | array[0] = staProtocol.getWorkNo(); |
| | | array[1] = staProtocol.getStaNo(); |
| | | |
| | | OperateResult writeResult; |
| | | //任务下发次数 |
| | | int writeCount = 0; |
| | | //任务下发成功标识 |
| | | boolean writeFlag = false; |
| | | while(writeCount < 5){ |
| | | writeResult = siemensS7Net.Write("DB100." + index*4, array); // 工作号、目标站 |
| | | |
| | | if(writeResult.IsSuccess){ |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB100." + index*4, (short)4); |
| | | if(readResult.IsSuccess){ |
| | | short workNo = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 0); |
| | | short staNo = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 2); |
| | | if(staProtocol.getWorkNo().equals(workNo) && staProtocol.getStaNo().equals(staNo)){ |
| | | //任务命令写入成功 |
| | | writeFlag = true; |
| | | log.info("写入输送线命令后返回成功,并且回读成功。输送线plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | |
| | | Date now = new Date(); |
| | | break; |
| | | } else {//返回结果是成功了,但是真实值不相同 |
| | | writeCount++; |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线命令后返回成功,但是读取任务值不一致。输送线plc编号={1},站点数据={2},写入次数={3}", |
| | | slave.getId(), JSON.toJSON(staProtocol),writeCount)); |
| | | log.error("写入输送线命令后返回成功,但是读取任务值不一致。输送线plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | |
| | | } |
| | | } else { |
| | | writeCount++; |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线命令后读取失败。输送线plc编号={1},站点数据={2},写入次数={3}", |
| | | slave.getId(), JSON.toJSON(staProtocol), writeCount)); |
| | | log.error("写入输送线命令后读取失败。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | |
| | | } |
| | | } else { |
| | | writeCount++; |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线命令失败。输送线plc编号={1},站点数据={2},写入次数={3}", |
| | | slave.getId(), JSON.toJSON(staProtocol),writeCount)); |
| | | log.error("写入输送线命令失败。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | |
| | | } |
| | | Thread.sleep(200); |
| | | } |
| | | |
| | | //写命令尝试了5次还是失败了 |
| | | if(!writeFlag){ |
| | | staProtocol = station.get(staProtocol.getSiteId()); |
| | | if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | 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(3, staProtocol)); |
| | | read();//读取1次设备状态 |
| | | return; |
| | | } else { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发成功 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol))); |
| | | //log.info("输送线命令下发 [id:{}] >>>>> 命令下发成功: {}", slave.getId(), JSON.toJSON(staProtocol)); |
| | | |
| | | Integer siteId = staProtocol.getSiteId(); |
| | | staProtocol = station.get(siteId); |
| | | if ((siteId == 101 || siteId == 201)&&(staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0)) { |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |