| | |
| | | import com.zy.core.action.ForkLiftAction; |
| | | import com.zy.core.action.ShuttleAction; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.ForkLiftIoModeType; |
| | | import com.zy.core.enums.ForkLiftProtocolStatusType; |
| | | import com.zy.core.enums.ForkLiftTaskModeType; |
| | | import com.zy.core.enums.RedisKeyType; |
| | |
| | | @Override |
| | | public boolean connect() { |
| | | boolean result = false; |
| | | siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500, slave.getIp()); |
| | | siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, slave.getIp()); |
| | | siemensS7Net.setRack(slave.getRack().byteValue()); |
| | | siemensS7Net.setSlot(slave.getSlot().byteValue()); |
| | | OperateResult connect = siemensS7Net.ConnectServer(); |
| | | if(connect.IsSuccess){ |
| | | result = true; |
| | | OutputQueue.DEVP.offer(MessageFormat.format( "【{0}】货叉提升机连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format( "【{0}】货叉提升机连接成功 ===>> [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.info("货叉提升机连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } else { |
| | | OutputQueue.DEVP.offer(MessageFormat.format( "【{0}】货叉提升机连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format( "【{0}】货叉提升机连接失败!!! ===>> [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("货叉提升机连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | // siemensS7Net.ConnectClose(); |
| | |
| | | private void readStatus() { |
| | | try { |
| | | //获取提升机数据 |
| | | OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB101.0", (short) 32); |
| | | OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB101.0", (short) 16); |
| | | if (result1.IsSuccess) { |
| | | if (null == forkLiftProtocol) { |
| | | forkLiftProtocol = new ForkLiftProtocol(); |
| | |
| | | //模式 |
| | | forkLiftProtocol.setModel((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 0)); |
| | | //PLC任务号 |
| | | forkLiftProtocol.setWrkNo((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 4)); |
| | | forkLiftProtocol.setWrkNo((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 2)); |
| | | //任务状态 |
| | | forkLiftProtocol.setProtocolStatus((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 8)); |
| | | forkLiftProtocol.setProtocolStatus((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 4)); |
| | | //任务模式 |
| | | forkLiftProtocol.setModel((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 12)); |
| | | forkLiftProtocol.setTaskMode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 6)); |
| | | //取货数据 |
| | | forkLiftProtocol.setPick((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 16)); |
| | | forkLiftProtocol.setPick((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 8)); |
| | | //放货数据 |
| | | forkLiftProtocol.setPut((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 20)); |
| | | forkLiftProtocol.setPut((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 10)); |
| | | //出入库模式 |
| | | forkLiftProtocol.setIOMode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 24)); |
| | | forkLiftProtocol.setIOMode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 12)); |
| | | //故障码 |
| | | forkLiftProtocol.setErrorCode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 28)); |
| | | forkLiftProtocol.setErrorCode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 14)); |
| | | |
| | | //************补充扩展字段************* |
| | | InnerForkLiftExtend forkLiftExtend = (InnerForkLiftExtend) forkLiftProtocol.getExtend(); |
| | |
| | | |
| | | }else { |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】{1}读取货叉提升机状态信息失败", DateUtils.convert(new Date()), slave.getId())); |
| | | } |
| | | |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB102.0", (short) 8); |
| | | if (result2.IsSuccess) { |
| | | for (int i = 0; i < this.slave.getSta().size(); i++) { |
| | | ForkLiftSlave.Sta sta = this.slave.getSta().get(i); |
| | | if (forkLiftStaProtocols.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | ForkLiftStaProtocol forkLiftStaProtocol = forkLiftStaProtocols.get(i); |
| | | boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result2.Content, i * 2, 2); |
| | | forkLiftStaProtocol.setHasTray(status1[0]); |
| | | forkLiftStaProtocol.setHasCar(status1[1]); |
| | | } |
| | | } |
| | | |
| | | if (System.currentTimeMillis() - forkLiftProtocol.getDeviceDataLog() > 1000 * 5) { |
| | |
| | | array[3] = command.getPut();//放货数据 |
| | | OperateResult result = siemensS7Net.Write("DB103.0", array); |
| | | if (result.IsSuccess) { |
| | | OperateResult result2 = siemensS7Net.Write("DB103.16", command.getConfirm()); |
| | | OperateResult result2 = siemensS7Net.Write("DB103.8", command.getConfirm()); |
| | | if (result2.IsSuccess) { |
| | | response.setResult(true); |
| | | } |
| | |
| | | array[3] = command.getPut();//放货数据 |
| | | OperateResult result = siemensS7Net.Write("DB103.0", array); |
| | | if (result.IsSuccess) { |
| | | OperateResult result2 = siemensS7Net.Write("DB103.16", command.getConfirm()); |
| | | OperateResult result2 = siemensS7Net.Write("DB103.8", command.getConfirm()); |
| | | if (result2.IsSuccess) { |
| | | response.setResult(true); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public CommandResponse reset(ForkLiftCommand command) { |
| | | public CommandResponse reset() { |
| | | CommandResponse response = new CommandResponse(false); |
| | | OperateResult result = siemensS7Net.Write("DB103.10", (short) 1); |
| | | if (result.IsSuccess) { |
| | | News.info("货叉提升机确认命令下发成功,提升机号={}", forkLiftProtocol.getLiftNo()); |
| | | response.setResult(true); |
| | | } |
| | | return response; |
| | | } |
| | | |
| | |
| | | public boolean isIdle() { |
| | | if (this.forkLiftProtocol.getTaskNo() == null |
| | | || this.forkLiftProtocol.getProtocolStatus() == null |
| | | || this.forkLiftProtocol.getModel() == null |
| | | || this.forkLiftProtocol.getErrorCode() == null |
| | | ) { |
| | | return false; |
| | | } |
| | | |
| | | boolean res = this.forkLiftProtocol.getProtocolStatus() == ForkLiftProtocolStatusType.IDLE.id |
| | | && this.forkLiftProtocol.getTaskNo() == 0; |
| | | && this.forkLiftProtocol.getWrkNo() == 0 |
| | | && this.forkLiftProtocol.getTaskNo() == 0 |
| | | && this.forkLiftProtocol.getModel() == 2 |
| | | && this.forkLiftProtocol.getErrorCode() == 0 |
| | | ; |
| | | return res; |
| | | } |
| | | |
| | | @Override |
| | | public boolean isDeviceIdle() { |
| | | return false; |
| | | return isDeviceIdle(null); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isDeviceIdle(ExecuteSupport support) { |
| | | return false; |
| | | if (null != support) { |
| | | Boolean judgement = support.judgement(); |
| | | if (judgement != null && !judgement) { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | if (this.forkLiftProtocol.getTaskNo() == null |
| | | || this.forkLiftProtocol.getProtocolStatus() == null |
| | | || this.forkLiftProtocol.getModel() == null |
| | | || this.forkLiftProtocol.getErrorCode() == null |
| | | ) { |
| | | return false; |
| | | } |
| | | |
| | | boolean res = this.forkLiftProtocol.getProtocolStatus() == ForkLiftProtocolStatusType.IDLE.id |
| | | && this.forkLiftProtocol.getWrkNo() == 0 |
| | | && this.forkLiftProtocol.getModel() == 2 |
| | | && this.forkLiftProtocol.getErrorCode() == 0 |
| | | ; |
| | | return res; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean switchIOMode(ForkLiftIoModeType type) { |
| | | OperateResult result = siemensS7Net.Write("DB103.12", type.id.shortValue()); |
| | | if (result.IsSuccess) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public int generateDeviceTaskNo(int taskNo, ForkLiftTaskModeType type) { |
| | | return taskNo; |
| | | } |
| | | |
| | | @Override |
| | | public List<ForkLiftCommand> getPickAndPutCommand(Integer taskNo, Integer pick, Integer put) { |
| | | Integer realPick = pick % 1000; |
| | | Integer realPut = put % 1000; |
| | | |
| | | List<ForkLiftCommand> commands = new ArrayList<>(); |
| | | ForkLiftCommand command = new ForkLiftCommand(); |
| | | command.setLiftNo(slave.getId()); |
| | | command.setTaskNo(taskNo.shortValue()); |
| | | command.setMode(ForkLiftTaskModeType.PICK_PUT.id.shortValue()); |
| | | command.setPick(pick.shortValue()); |
| | | command.setPut(put.shortValue()); |
| | | command.setPick(realPick.shortValue()); |
| | | command.setPut(realPut.shortValue()); |
| | | command.setConfirm((short) 1); |
| | | |
| | | commands.add(command); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<ForkLiftCommand> getShuttleSwitchCommand(Integer taskNo, Integer originLev, Integer targetLev) { |
| | | public List<ForkLiftCommand> getShuttleSwitchCommand(Integer taskNo, Integer pick, Integer put) { |
| | | Integer realPick = pick % 1000; |
| | | Integer realPut = put % 1000; |
| | | |
| | | List<ForkLiftCommand> commands = new ArrayList<>(); |
| | | ForkLiftCommand command = new ForkLiftCommand(); |
| | | command.setLiftNo(slave.getId()); |
| | | command.setTaskNo(taskNo.shortValue()); |
| | | command.setMode(ForkLiftTaskModeType.SHUTTLE_SWITCH.id.shortValue()); |
| | | command.setPick(originLev.shortValue()); |
| | | command.setPut(targetLev.shortValue()); |
| | | command.setPick(realPick.shortValue()); |
| | | command.setPut(realPut.shortValue()); |
| | | command.setConfirm((short) 1); |
| | | |
| | | commands.add(command); |