| | |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.BasRgv; |
| | |
| | | import com.zy.core.model.protocol.RgvProtocol; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | |
| | | command = new RgvCommand(); |
| | | } |
| | | command.setRgvNo(slave.getId()); // RGV编号 |
| | | command.setTaskNo1((short) 0); // 工作号 |
| | | command.setAckFinish1((short) 1); // 任务完成确认位 |
| | | command.setTaskNo1( 0); // 工作号 |
| | | command.setAckFinish1(true); // 任务完成确认位 |
| | | command.setTaskMode1(RgvTaskModeType.NONE); // 任务模式 |
| | | command.setSourceStaNo1((short)0); // 源站 |
| | | command.setDestinationStaNo1((short)0); // 目标站 |
| | |
| | | commandAvoidanceXY = new RgvCommand(); |
| | | } |
| | | commandAvoidanceXY.setRgvNo(slave.getId()); // RGV编号 |
| | | commandAvoidanceXY.setTaskNo1((short) 9999); // 工作号 |
| | | commandAvoidanceXY.setAckFinish1((short) 1); // 任务完成确认位 |
| | | commandAvoidanceXY.setTaskNo1( 9999); // 工作号 |
| | | commandAvoidanceXY.setAckFinish1(true); // 任务完成确认位 |
| | | commandAvoidanceXY.setTaskMode1(RgvTaskModeType.GO_ORIGIN); // 任务模式 |
| | | commandAvoidanceXY.setSourceStaNo1((short)0); // 源站 |
| | | commandAvoidanceXY.setDestinationStaNo1((short)0); // 目标站 |
| | |
| | | // commandAvoidanceXY.setDestinationStaNo2((short)0); // 目标站 |
| | | commandAvoidanceXY.setCommand((short)0); |
| | | write(commandAvoidanceXY); |
| | | break; |
| | | case 10: |
| | | write10((String) task.getData()); |
| | | break; |
| | | //单机写入数据 |
| | | case 11: |
| | | write11((RgvCommand) task.getData()); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | } |
| | | rgvProtocol.setMode((short) -1); |
| | | rgvProtocol.setStatus((short)-1); |
| | | rgvProtocol.setTaskNo1((short)0); |
| | | rgvProtocol.setTaskNo1(0); |
| | | rgvProtocol.setStatus1((short)-1); |
| | | rgvProtocol.setLoaded1((short)0); |
| | | rgvProtocol.setWalkPos((short)0); |
| | |
| | | // rgvProtocol.setStatus2((short)-1); |
| | | // rgvProtocol.setLoaded2((short)0); |
| | | rgvProtocol.setAlarm((short)0); |
| | | rgvProtocol.setxSpeed((short) 0); |
| | | rgvProtocol.setxDistance((short) 0); |
| | | rgvProtocol.setxDuration((short) 0); |
| | | rgvProtocol.setXSpeed(0.0F); |
| | | rgvProtocol.setXDistance(0.0F); |
| | | rgvProtocol.setXDuration(0.0F); |
| | | rgvProtocol.setSouSta((short)0); |
| | | rgvProtocol.setEndSta((short)0); |
| | | rgvProtocol.setList32(new boolean[8]); |
| | | rgvProtocol.setRgvPos(8000); |
| | | } |
| | | |
| | | @Override |
| | |
| | | */ |
| | | private void readStatus(){ |
| | | try { |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB100.0", (short) 16); |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 36); |
| | | if (result.IsSuccess) { |
| | | if (null == rgvProtocol || rgvProtocol.getRgvNo() == null) { |
| | | rgvProtocol = new RgvProtocol(); |
| | | rgvProtocol.setRgvNo(slave.getId()); |
| | | } |
| | | rgvProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0)); |
| | | rgvProtocol.setSouSta(siemensNet.getByteTransform().TransInt16(result.Content, 2)); |
| | | rgvProtocol.setEndSta(siemensNet.getByteTransform().TransInt16(result.Content, 4)); |
| | | rgvProtocol.setTaskNo1(siemensNet.getByteTransform().TransInt16(result.Content, 6)); |
| | | rgvProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 8)); |
| | | rgvProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 10)); |
| | | rgvProtocol.setSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 12)); |
| | | rgvProtocol.setRgvPos((int) siemensNet.getByteTransform().TransInt16(result.Content, 14)); |
| | | rgvProtocol.setTaskNo1(siemensNet.getByteTransform().TransInt32(result.Content, 2)); |
| | | // rgvProtocol.setTaskNo1(siemensNet.getByteTransform().TransInt16(result.Content, 4)); |
| | | rgvProtocol.setStatus1(siemensNet.getByteTransform().TransInt16(result.Content, 6)); |
| | | rgvProtocol.setRgvPos((int) siemensNet.getByteTransform().TransInt16(result.Content, 8)); |
| | | rgvProtocol.setWalkPos(siemensNet.getByteTransform().TransInt16(result.Content, 10)); |
| | | rgvProtocol.setCode(siemensNet.getByteTransform().TransInt32(result.Content, 12)); |
| | | rgvProtocol.setLoaded1(siemensNet.getByteTransform().TransInt16(result.Content, 16)); |
| | | rgvProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 18)); |
| | | rgvProtocol.setXSpeed(siemensNet.getByteTransform().TransSingle(result.Content, 20)); |
| | | rgvProtocol.setXDistance(siemensNet.getByteTransform().TransSingle(result.Content, 24)); |
| | | rgvProtocol.setXDuration(siemensNet.getByteTransform().TransSingle(result.Content, 28)); |
| | | rgvProtocol.setList32(siemensNet.getByteTransform().TransBool(result.Content, 32, 1)); |
| | | rgvProtocol.setList33(siemensNet.getByteTransform().TransBool(result.Content, 33, 1)); |
| | | rgvProtocol.setList34(siemensNet.getByteTransform().TransBool(result.Content, 34, 1)); |
| | | rgvProtocol.setList35(siemensNet.getByteTransform().TransBool(result.Content, 35, 1)); |
| | | |
| | | |
| | | |
| | | |
| | | OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功", DateUtils.convert(new Date()), slave.getId())); |
| | |
| | | result = siemensNet.Write("DB99.0.3", true); |
| | | } |
| | | else if (command.isReset()) { |
| | | siemensNet.Write("DB99.0.3", false); |
| | | Thread.sleep(100); |
| | | result = siemensNet.Write("DB99.0.4", true); |
| | | } |
| | | else if (command.isNoStop()) { |
| | | result = siemensNet.Write("DB99.0.3", false); |
| | | } |
| | | |
| | | // if (command.getAckFinish1() == 0 && command.getAckFinish2() == 0) { |
| | |
| | | log.error("RGV写入命令为空"); |
| | | return false; |
| | | } |
| | | |
| | | // siemensNet.Write("DB100.20", command.getCommand()); |
| | | siemensNet.Write("DB100.16", false); |
| | | |
| | | command.setRgvNo(slave.getId()); |
| | | short[] array = new short[5]; |
| | | array[0] = command.getAckFinish1(); |
| | | array[1] = command.getTaskNo1(); |
| | | short[] array = new short[4]; |
| | | array[0] = command.getSourceStaNo1(); |
| | | array[1] = command.getDestinationStaNo1(); |
| | | array[2] = command.getTaskMode1(); |
| | | array[3] = command.getSourceStaNo1(); |
| | | array[4] = command.getDestinationStaNo1(); |
| | | siemensNet.Write("DB100.10", command.getCommand()); |
| | | // array[4] = command.getTaskNo1().shortValue(); |
| | | OperateResult result1 = siemensNet.Write("DB100.0",command.isAckFinish1()); |
| | | OperateResult result2 = siemensNet.Write("DB100.2", array); |
| | | OperateResult result3 = siemensNet.Write("DB100.8", command.getTaskNo1()); |
| | | // OperateResult result3 = siemensNet.Write("DB100.14.1", command.getAckFinish1() != 0); |
| | | |
| | | OperateResult result = siemensNet.Write("DB100.0", array); |
| | | |
| | | if (!result.IsSuccess){ |
| | | if (!result1.IsSuccess && !result2.IsSuccess){ |
| | | log.error("写入RGVplc数据失败,重新添加任务到队列 ===> [id:{}],{}",slave.getId(),JSON.toJSON(command)); |
| | | MessageQueue.offer(SlaveType.Rgv,slave.getId(),new Task(4,command)); |
| | | Thread.sleep(100); |
| | |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 12); |
| | | if (resultRead.IsSuccess){ |
| | | RgvCommand one = new RgvCommand(); |
| | | // one.setAckFinish1(siemensNet.getByteTransform().TransInt16(resultRead.Content, 0)); |
| | | one.setTaskNo1(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); |
| | | one.setTaskMode1(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4)); |
| | | one.setSourceStaNo1(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); |
| | | one.setDestinationStaNo1(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); |
| | | if ( |
| | | one.setAckFinish1(siemensNet.getByteTransform().TransBool(resultRead.Content, 0)); |
| | | one.setSourceStaNo1(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); |
| | | one.setDestinationStaNo1(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4)); |
| | | one.setTaskMode1(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); |
| | | one.setTaskNo1(siemensNet.getByteTransform().TransInt32(resultRead.Content, 8)); |
| | | // one.setDestinationStaNo1(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); |
| | | if ( !command.isAckFinish1() == one.isAckFinish1() || |
| | | !command.getTaskNo1().equals(one.getTaskNo1()) || |
| | | !command.getTaskMode1().equals(one.getTaskMode1()) || |
| | | !command.getSourceStaNo1().equals(one.getSourceStaNo1()) || |
| | |
| | | log.error("RGV命令地址写入后回读出错"); |
| | | } |
| | | |
| | | if (command.getAckFinish1() == 0) { |
| | | if (result.IsSuccess) { |
| | | if (!command.isAckFinish1()) { |
| | | if (result1.IsSuccess) { |
| | | Thread.sleep(300); |
| | | //任务下发次数 |
| | | int writeCount2 = 0; |
| | | |
| | | do { |
| | | writeCount2++; |
| | | short commandFinish = (short) 1; |
| | | result = siemensNet.Write("DB100.10", commandFinish); |
| | | if(result.IsSuccess){ |
| | | result1 = siemensNet.Write("DB100.16", true); |
| | | if(result1.IsSuccess){ |
| | | //RGV任务写入后,回读一次,看是否成功 |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.10", (short) 2); |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.16", (short) 2); |
| | | if (resultRead.IsSuccess) { |
| | | commandFinish=siemensNet.getByteTransform().TransInt16(resultRead.Content, 0); |
| | | if (commandFinish != 1){ |
| | | boolean commandFinish=siemensNet.getByteTransform().TransBool(resultRead.Content, 0); |
| | | if (!commandFinish){ |
| | | log.error("RGV任务确认位"+commandFinish+"写入数据与回读数据不一致!"+"循环执行次数:"+writeCount2+"次"); |
| | | }else{ |
| | | //任务命令写入成功 |
| | |
| | | break; |
| | | } |
| | | }else { |
| | | log.error("RGV任务确认位"+commandFinish+"回读失败!"+"循环执行次数:"+writeCount2+"次"); |
| | | log.error("RGV任务确认位回读失败!"+"循环执行次数:"+writeCount2+"次"); |
| | | } |
| | | } else { |
| | | log.error("RGV任务确认位"+commandFinish+"写入失败!"+"循环执行次数:"+writeCount2+"次"); |
| | | log.error("RGV任务确认位写入失败!"+"循环执行次数:"+writeCount2+"次"); |
| | | } |
| | | }while (writeCount2<5); |
| | | } |
| | | } |
| | | |
| | | // if (command.getAckFinish1() == 0) { |
| | | // short commandFinish = 1; //工位1任务写入 |
| | | // Thread.sleep(200); |
| | | // result = siemensNet.Write("DB100.10", commandFinish); |
| | | // } |
| | | |
| | | |
| | | |
| | | if (result != null && result.IsSuccess) { |
| | | if (result1 != null && result1.IsSuccess) { |
| | | Thread.sleep(200); |
| | | this.readStatus(); |
| | | log.info("RGV 工位1命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); |
| | |
| | | } |
| | | } |
| | | |
| | | //小车强制、复位、报警消音、启动、停止、急停、复位、手动、手动定位、单机、联机、货叉回中 |
| | | private boolean write10(String status) throws InterruptedException { |
| | | if (Cools.isEmpty(status)) { |
| | | log.error("RGV写入命令为空"); |
| | | return false; |
| | | } |
| | | OperateResult result = siemensNet.Write("DB19."+status, true); |
| | | if (result != null && result.IsSuccess) { |
| | | Thread.sleep(200); |
| | | this.readStatus(); |
| | | log.info("RGV 命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON("DB19."+status)); |
| | | OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), "DB19."+status)); |
| | | return true; |
| | | } else { |
| | | OutputQueue.RGV.offer(MessageFormat.format("【{0}】写入RGV plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [DB块:{4}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), "DB19."+status)); |
| | | log.error("写入RGV plc数据失败 ===>> [id:{}] [ip:{}] [port:{}] [DB块:{4}]", slave.getId(), slave.getIp(), slave.getPort(), "DB19."+status); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | //单步任务 |
| | | private boolean write11(RgvCommand command) throws InterruptedException { |
| | | if (null == command) { |
| | | log.error("RGV写入命令为空"); |
| | | return false; |
| | | } |
| | | String status = ""; |
| | | command.setRgvNo(slave.getId()); |
| | | short[] array = new short[2]; |
| | | array[0] = command.getDestinationStaNo1(); |
| | | array[1] = command.getSourceStaNo1(); |
| | | |
| | | OperateResult result = siemensNet.Write("DB19.0", array); |
| | | if (command.getTaskMode1().equals(RgvTaskModeType.FETCH.id.shortValue())){ |
| | | status = "4.1"; |
| | | } else if (command.getTaskMode1().equals(RgvTaskModeType.PUT.id.shortValue())){ |
| | | status = "4.2"; |
| | | } else if (command.getTaskMode1().equals(RgvTaskModeType.X_MOVE.id.shortValue())){ |
| | | status = "4.0"; |
| | | } else if (command.getTaskMode1().equals(RgvTaskModeType.FETCH_PUT.id.shortValue())){ |
| | | status = "4.3"; |
| | | } else { |
| | | OutputQueue.RGV.offer(MessageFormat.format("【{0}】写入RGV plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [DB块:{4}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), "DB19."+status)); |
| | | log.error("写入RGV plc数据失败 未知任务类型 ===>> [id:{}] [ip:{}] [port:{}] [DB块:{4}]", slave.getId(), slave.getIp(), slave.getPort(), "DB19."+status); |
| | | return false; |
| | | } |
| | | OperateResult result1 = siemensNet.Write("DB19."+status, true); |
| | | if (result != null && result.IsSuccess && result1 != null && result1.IsSuccess) { |
| | | Thread.sleep(200); |
| | | this.readStatus(); |
| | | log.info("RGV 命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON("DB19."+status)); |
| | | OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), "DB19."+status)); |
| | | return true; |
| | | } else { |
| | | OutputQueue.RGV.offer(MessageFormat.format("【{0}】写入RGV plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [DB块:{4}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), "DB19."+status)); |
| | | log.error("写入RGV plc数据失败 ===>> [id:{}] [ip:{}] [port:{}] [DB块:{4}]", slave.getId(), slave.getIp(), slave.getPort(), "DB19."+status); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void close() { |
| | | siemensNet.ConnectClose(); |