| | |
| | | package com.zy.core.thread.impl; |
| | | |
| | | import HslCommunication.Core.Types.OperateResult; |
| | | import HslCommunication.Core.Types.OperateResultExOne; |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | |
| | | import com.zy.common.ExecuteSupport; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.action.ForkLiftAction; |
| | | import com.zy.core.action.ShuttleAction; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.ForkLiftProtocolStatusType; |
| | | import com.zy.core.enums.ForkLiftTaskModeType; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.ForkLiftSlave; |
| | | import com.zy.core.model.command.ForkLiftCommand; |
| | |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | | return false; |
| | | boolean result = false; |
| | | siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500, 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())); |
| | | 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())); |
| | | News.error("货叉提升机连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | // siemensS7Net.ConnectClose(); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | |
| | | try { |
| | | read(); |
| | | Thread.sleep(200); |
| | | execute(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void execute() { |
| | | ForkLiftAction forkLiftAction = SpringUtils.getBean(ForkLiftAction.class); |
| | | if (forkLiftAction == null) { |
| | | return; |
| | | } |
| | | |
| | | Object object = redisUtil.get(RedisKeyType.FORK_LIFT_FLAG.key + slave.getId()); |
| | | if (object == null) { |
| | | return; |
| | | } |
| | | |
| | | Integer taskNo = Integer.valueOf(String.valueOf(object)); |
| | | if (taskNo != 0) { |
| | | //存在任务需要执行 |
| | | boolean result = forkLiftAction.executeWork(slave.getId(), taskNo); |
| | | } |
| | | } |
| | | |
| | |
| | | //----------读取提升机状态----------- |
| | | //模式 |
| | | forkLiftProtocol.setModel((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 0)); |
| | | //任务号 |
| | | forkLiftProtocol.setTaskNo((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 4)); |
| | | //PLC任务号 |
| | | forkLiftProtocol.setWrkNo((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 4)); |
| | | //任务状态 |
| | | forkLiftProtocol.setProtocolStatus((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 8)); |
| | | //任务模式 |
| | |
| | | |
| | | @Override |
| | | public CommandResponse pickAndPut(ForkLiftCommand command) { |
| | | return null; |
| | | CommandResponse response = new CommandResponse(false); |
| | | |
| | | short[] array = new short[4]; |
| | | array[0] = command.getTaskNo();//任务号 |
| | | array[1] = command.getMode();//任务模式 |
| | | array[2] = command.getPick();//取货数据 |
| | | array[3] = command.getPut();//放货数据 |
| | | OperateResult result = siemensS7Net.Write("DB103.0", array); |
| | | if (result.IsSuccess) { |
| | | OperateResult result2 = siemensS7Net.Write("DB103.16", command.getConfirm()); |
| | | if (result2.IsSuccess) { |
| | | response.setResult(true); |
| | | } |
| | | } |
| | | return response; |
| | | } |
| | | |
| | | @Override |
| | | public CommandResponse shuttleSwitch(ForkLiftCommand command) { |
| | | return null; |
| | | CommandResponse response = new CommandResponse(false); |
| | | |
| | | short[] array = new short[4]; |
| | | array[0] = command.getTaskNo();//任务号 |
| | | array[1] = command.getMode();//任务模式 |
| | | array[2] = command.getPick();//取货数据 |
| | | array[3] = command.getPut();//放货数据 |
| | | OperateResult result = siemensS7Net.Write("DB103.0", array); |
| | | if (result.IsSuccess) { |
| | | OperateResult result2 = siemensS7Net.Write("DB103.16", command.getConfirm()); |
| | | if (result2.IsSuccess) { |
| | | response.setResult(true); |
| | | } |
| | | } |
| | | return response; |
| | | } |
| | | |
| | | @Override |
| | | public CommandResponse reset(ForkLiftCommand command) { |
| | | return null; |
| | | public CommandResponse reset() { |
| | | CommandResponse response = new CommandResponse(false); |
| | | OperateResult result = siemensS7Net.Write("DB103.20", (short) 1); |
| | | if (result.IsSuccess) { |
| | | response.setResult(true); |
| | | } |
| | | return response; |
| | | } |
| | | |
| | | @Override |
| | | public boolean isIdle() { |
| | | return false; |
| | | if (this.forkLiftProtocol.getTaskNo() == null |
| | | || this.forkLiftProtocol.getProtocolStatus() == null |
| | | ) { |
| | | return false; |
| | | } |
| | | |
| | | boolean res = this.forkLiftProtocol.getProtocolStatus() == ForkLiftProtocolStatusType.IDLE.id |
| | | && this.forkLiftProtocol.getTaskNo() == 0; |
| | | return res; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public boolean setSyncTaskNo(Integer taskNo) { |
| | | return false; |
| | | this.forkLiftProtocol.setSyncTaskNo(taskNo); |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public int generateDeviceTaskNo(int taskNo, ForkLiftTaskModeType type) { |
| | | return 0; |
| | | return taskNo; |
| | | } |
| | | |
| | | @Override |