| | |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.BasCrnOpt; |
| | | import com.zy.asrs.entity.BasCrnp; |
| | | import com.zy.asrs.entity.BasErrLog; |
| | | import com.zy.asrs.service.BasCrnOptService; |
| | | import com.zy.asrs.service.BasCrnpService; |
| | | import com.zy.asrs.service.BasErrLogService; |
| | | import com.zy.asrs.service.DeviceErrorService; |
| | | import com.zy.core.CrnThread; |
| | | import com.zy.core.cache.CrnErrCache; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.CrnStatusType; |
| | |
| | | * 堆垛机是否在回原点运动中标记 |
| | | */ |
| | | private boolean backHpFlag = false; |
| | | public Long currentTimeMilliConnectCrn= 0L; |
| | | |
| | | public SiemensCrnThread(CrnSlave slave) { |
| | | this.slave = slave; |
| | |
| | | command.setDestinationPosZ((short)0); // 目标库位层 |
| | | write(command); |
| | | break; |
| | | // 复位 |
| | | case 4: |
| | | CrnCommand command4 = (CrnCommand) task.getData(); |
| | | write(command4); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | |
| | | crnProtocol.setyDistance((short) 0); |
| | | crnProtocol.setxDuration((short) 0); |
| | | crnProtocol.setyDuration((short) 0); |
| | | try{ |
| | | CrnErrCache.updateCrnErr(crnProtocol.getCrnNo(), "离线"); |
| | | } catch (Exception e1){ |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | */ |
| | | private void readStatus(){ |
| | | try { |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 56); |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 58); |
| | | if (result.IsSuccess) { |
| | | if (null == crnProtocol) { |
| | | crnProtocol = new CrnProtocol(); |
| | | crnProtocol.setCrnNo(slave.getId()); |
| | | } |
| | | crnProtocol.setCrnNo(slave.getId()); |
| | | crnProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0)); |
| | | crnProtocol.setTaskNo(siemensNet.getByteTransform().TransInt16(result.Content, 2)); |
| | | crnProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 4)); |
| | |
| | | crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 44)); |
| | | crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48)); |
| | | crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 52)); |
| | | crnProtocol.setLaneNo((int)siemensNet.getByteTransform().TransInt16(result.Content, 56));//巷道号 |
| | | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | |
| | | if(crnProtocol.getTaskNo()==9999){ |
| | | backHpFlag = false; |
| | | } |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setAckFinish((short)1); |
| | | if (write(crnCommand)) { |
| | | resetFlag = false; |
| | | |
| | | if (!Cools.isEmpty(crnProtocol.getLaneNo()) && crnProtocol.getLaneNo()!=0){ |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setAckFinish((short)1); |
| | | // crnCommand.setTaskNo(crnProtocol.getTaskNo()); |
| | | crnCommand.setLaneNo(crnProtocol.getLaneNo()); |
| | | crnCommand.setTaskMode(CrnTaskModeType.NONE); // 任务模式 |
| | | if (write(crnCommand)) { |
| | | resetFlag = false; |
| | | } |
| | | } else { |
| | | CrnErrCache.updateCrnErr(crnProtocol.getCrnNo(), "巷道号为0"); |
| | | } |
| | | } |
| | | } |
| | |
| | | initCrn(); |
| | | OutputQueue.CRN.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()); |
| | | if (System.currentTimeMillis()-currentTimeMilliConnectCrn>1000*60*10){ |
| | | try{ |
| | | DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); |
| | | deviceErrorService.addDeviceError("CrnErr", slave.getId(), "读取堆垛机plc状态信息失败"); |
| | | } catch (Exception e2){ |
| | | Thread.sleep(1000); |
| | | // log.error("e2:"+e2.getMessage()); |
| | | } |
| | | if (currentTimeMilliConnectCrn == 0){ |
| | | currentTimeMilliConnectCrn = System.currentTimeMillis()-1000*60*10-1; |
| | | } else { |
| | | currentTimeMilliConnectCrn = System.currentTimeMillis(); |
| | | |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | log.error("堆垛机写入命令为空"); |
| | | return false; |
| | | } |
| | | CrnErrCache.updateCrnErr(slave.getId(), "-"); |
| | | try{ |
| | | DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); |
| | | deviceErrorService.addDeviceError("crnWrite", slave.getId(), "巷道号"+command.getLaneNo()+";堆垛机指令下发:"+JSON.toJSONString(command.getNowTask())); |
| | | } catch (Exception e2){ |
| | | } |
| | | // try{ |
| | | // BasErrLogService basErrLogService = SpringUtils.getBean(BasErrLogService.class); |
| | | // BasErrLog basErrLog = new BasErrLog(command,"","任务下发记录"); |
| | | // if (!basErrLogService.insert(basErrLog)) { |
| | | // log.error("堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", slave.getId(), "任务下发记录失败"); |
| | | // } |
| | | // } catch (Exception e3){ |
| | | // } |
| | | // convertRow(command); |
| | | command.setCrnNo(slave.getId()); |
| | | short[] array = new short[10]; |
| | |
| | | array[6] = command.getDestinationPosX(); |
| | | array[7] = command.getDestinationPosY(); |
| | | array[8] = command.getDestinationPosZ(); |
| | | // array[9] = command.getSourceStaNo(); |
| | | // array[10] = command.getDestinationStaNo(); |
| | | array[9] = command.getCommand(); |
| | | // array[9] = command.getCommand(); |
| | | array[9] = (short)0; |
| | | OperateResult result18 = siemensNet.Write("DB100.18", (short)0); |
| | | try{ |
| | | Thread.sleep(50L); |
| | | } catch (Exception e){} |
| | | |
| | | OperateResult result = siemensNet.Write("DB100.0", array); |
| | | |
| | | int i=0; |
| | | do{ |
| | | //堆垛机任务写入后,回读一次,看是否成功 |
| | | try{ |
| | | Thread.sleep(100L); |
| | | } catch (Exception e){} |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20); |
| | | if (resultRead.IsSuccess) { |
| | | CrnCommand one = new CrnCommand(); |
| | | one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); |
| | | one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4)); |
| | | one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); |
| | | one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); |
| | | one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10)); |
| | | one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12)); |
| | | one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14)); |
| | | one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16)); |
| | | if (!command.getTaskNo().equals(one.getTaskNo()) |
| | | || !command.getTaskMode().equals(one.getTaskMode()) |
| | | || !command.getSourcePosX().equals(one.getSourcePosX()) |
| | | || !command.getSourcePosY().equals(one.getSourcePosY()) |
| | | || !command.getSourcePosZ().equals(one.getSourcePosZ()) |
| | | || !command.getDestinationPosX().equals(one.getDestinationPosX()) |
| | | || !command.getDestinationPosY().equals(one.getDestinationPosY()) |
| | | || !command.getDestinationPosZ().equals(one.getDestinationPosZ()) |
| | | ){ |
| | | i++; |
| | | CrnErrCache.updateCrnErr(slave.getId(), "堆垛机命令地址写入后回读失败"); |
| | | |
| | | log.error("堆垛机命令地址写入后回读失败[id:{}]>>>>重写[{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), i,JSON.toJSON(command),JSON.toJSON(one)); |
| | | |
| | | try{ |
| | | DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); |
| | | deviceErrorService.addDeviceError("CrnErr", slave.getId(), "巷道号"+command.getLaneNo()+";写入次数"+i+";堆垛机命令地址写入后回读失败:"+JSON.toJSONString(command.getNowTask())); |
| | | } catch (Exception e2){ |
| | | } |
| | | try{ |
| | | BasErrLogService basErrLogService = SpringUtils.getBean(BasErrLogService.class); |
| | | BasErrLog basErrLog = new BasErrLog(command,"堆垛机命令地址写入后回读失败",""); |
| | | if (!basErrLogService.insert(basErrLog)) { |
| | | log.error("堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", slave.getId(), "堆垛机命令地址写入后回读失败记录失败"); |
| | | } |
| | | } catch (Exception e3){ |
| | | } |
| | | result = siemensNet.Write("DB100.0", array); |
| | | }else{ |
| | | break; |
| | | } |
| | | } |
| | | }while(i<5); |
| | | |
| | | if (command.getAckFinish() == 0) { |
| | | short commandFinish = 1; |
| | | Thread.sleep(100L); |
| | | try{ |
| | | Thread.sleep(100L); |
| | | } catch (Exception e){} |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | int signFinish = 1; |
| | | while (signFinish<5){ |
| | | OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.18", (short) 2); |
| | | short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0); |
| | | if (transInt16 != commandFinish){ |
| | | log.info("下发DB100.18 回读失败" + "commandFinish:"+commandFinish); |
| | | log.info("下发DB100.18 回读失败" + "array:"+ JSON.toJSONString(array)); |
| | | CrnErrCache.updateCrnErr(slave.getId(), "下发DB100.18 回读失败"); |
| | | try{ |
| | | DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); |
| | | deviceErrorService.addDeviceError("CrnErr", slave.getId(), "巷道号"+command.getLaneNo()+";写入次数"+signFinish+";下发DB100.18 回读失败:"+JSON.toJSONString(command.getNowTask())); |
| | | } catch (Exception e2){ |
| | | } |
| | | try{ |
| | | BasErrLogService basErrLogService = SpringUtils.getBean(BasErrLogService.class); |
| | | BasErrLog basErrLog = new BasErrLog(command,"下发DB100.18 回读失败",""); |
| | | if (!basErrLogService.insert(basErrLog)) { |
| | | log.error("堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", slave.getId(), "下发DB100.18 回读失败记录失败"); |
| | | } |
| | | } catch (Exception e3){ |
| | | } |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | signFinish++; |
| | | }else { |
| | | log.info("下发DB100.18" + "commandFinish:"+commandFinish); |
| | | log.info("下发DB100.18" + "array:"+ JSON.toJSONString(array)); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | try { |
| | |
| | | } else { |
| | | OutputQueue.CRN.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()); |
| | | CrnErrCache.updateCrnErr(slave.getId(), "写入堆垛机plc数据失败"); |
| | | |
| | | return false; |
| | | } |
| | | } |
| | |
| | | isRunning = false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 清除作业启动中 |
| | | */ |
| | | @Override |
| | | public void setWrkSign() { |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 清除作业启动中 |
| | | */ |
| | | @Override |
| | | public void setResetFlag(boolean flag) { |
| | | this.resetFlag = flag; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 清除作业启动中 |
| | | */ |
| | | @Override |
| | | public boolean getResetFlag() { |
| | | return resetFlag; |
| | | } |
| | | |
| | | } |