| | |
| | | import com.zy.core.enums.CrnStatusType; |
| | | import com.zy.core.enums.CrnTaskModeType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.CrnSlave; |
| | | import com.zy.core.model.SteSlave; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.CrnCommand; |
| | | import com.zy.core.model.protocol.CrnProtocol; |
| | | import com.zy.core.model.command.SteCommand; |
| | | import com.zy.core.model.protocol.SteProtocol; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | break; |
| | | // 写入数据 |
| | | case 2: |
| | | write((CrnCommand) task.getData()); |
| | | write((SteCommand) task.getData()); |
| | | break; |
| | | // 复位 |
| | | case 3: |
| | | CrnCommand command = (CrnCommand) task.getData(); |
| | | SteCommand command = (SteCommand) task.getData(); |
| | | if (null == command) { |
| | | command = new CrnCommand(); |
| | | command = new SteCommand(); |
| | | } |
| | | command.setCrnNo(slave.getId()); // 堆垛机编号 |
| | | command.setTaskNo((short) 0); // 工作号 |
| | |
| | | // } |
| | | OperateResultExOne<byte[]> result = melsecMcNet.Read("D20", (short) 70); |
| | | if (result.IsSuccess) { |
| | | if (null == crnProtocol) { |
| | | crnProtocol = new CrnProtocol(); |
| | | if (null == steProtocol) { |
| | | steProtocol = new SteProtocol(); |
| | | } |
| | | crnProtocol.setMode(melsecMcNet.getByteTransform().TransInt16(result.Content, 0)); |
| | | crnProtocol.setTaskNo(melsecMcNet.getByteTransform().TransInt16(result.Content, 2)); |
| | | crnProtocol.setStatus(melsecMcNet.getByteTransform().TransInt16(result.Content, 4)); |
| | | crnProtocol.setBay(melsecMcNet.getByteTransform().TransInt16(result.Content, 6)); |
| | | crnProtocol.setLevel(melsecMcNet.getByteTransform().TransInt16(result.Content, 8)); |
| | | crnProtocol.setForkPos(melsecMcNet.getByteTransform().TransInt16(result.Content, 10)); |
| | | crnProtocol.setLiftPos(melsecMcNet.getByteTransform().TransInt16(result.Content, 12)); |
| | | crnProtocol.setWalkPos(melsecMcNet.getByteTransform().TransInt16(result.Content, 14)); |
| | | crnProtocol.setLoaded(melsecMcNet.getByteTransform().TransInt16(result.Content, 16)); |
| | | crnProtocol.setAlarm(melsecMcNet.getByteTransform().TransInt16(result.Content, 18)); |
| | | crnProtocol.setTemp1(melsecMcNet.getByteTransform().TransInt16(result.Content, 20)); |
| | | crnProtocol.setTemp2(melsecMcNet.getByteTransform().TransInt16(result.Content, 22)); |
| | | crnProtocol.setTemp3(melsecMcNet.getByteTransform().TransInt16(result.Content, 24)); |
| | | crnProtocol.setTemp4(melsecMcNet.getByteTransform().TransInt16(result.Content, 26)); |
| | | crnProtocol.setXSpeed(melsecMcNet.getByteTransform().TransSingle(result.Content, 28)); |
| | | crnProtocol.setYSpeed(melsecMcNet.getByteTransform().TransSingle(result.Content, 32)); |
| | | crnProtocol.setZSpeed(melsecMcNet.getByteTransform().TransSingle(result.Content, 36)); |
| | | crnProtocol.setXDistance(melsecMcNet.getByteTransform().TransSingle(result.Content, 40)); |
| | | crnProtocol.setYDistance(melsecMcNet.getByteTransform().TransSingle(result.Content, 44)); |
| | | crnProtocol.setXDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 48)); |
| | | crnProtocol.setYDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 52)); |
| | | steProtocol.setMode(melsecMcNet.getByteTransform().TransInt16(result.Content, 0)); |
| | | steProtocol.setTaskNo(melsecMcNet.getByteTransform().TransInt16(result.Content, 2)); |
| | | steProtocol.setStatus(melsecMcNet.getByteTransform().TransInt16(result.Content, 4)); |
| | | steProtocol.setBay(melsecMcNet.getByteTransform().TransInt16(result.Content, 6)); |
| | | steProtocol.setLevel(melsecMcNet.getByteTransform().TransInt16(result.Content, 8)); |
| | | steProtocol.setForkPos(melsecMcNet.getByteTransform().TransInt16(result.Content, 10)); |
| | | steProtocol.setLiftPos(melsecMcNet.getByteTransform().TransInt16(result.Content, 12)); |
| | | steProtocol.setWalkPos(melsecMcNet.getByteTransform().TransInt16(result.Content, 14)); |
| | | steProtocol.setLoaded(melsecMcNet.getByteTransform().TransInt16(result.Content, 16)); |
| | | steProtocol.setAlarm(melsecMcNet.getByteTransform().TransInt16(result.Content, 18)); |
| | | steProtocol.setTemp1(melsecMcNet.getByteTransform().TransInt16(result.Content, 20)); |
| | | steProtocol.setTemp2(melsecMcNet.getByteTransform().TransInt16(result.Content, 22)); |
| | | steProtocol.setTemp3(melsecMcNet.getByteTransform().TransInt16(result.Content, 24)); |
| | | steProtocol.setTemp4(melsecMcNet.getByteTransform().TransInt16(result.Content, 26)); |
| | | steProtocol.setXSpeed(melsecMcNet.getByteTransform().TransSingle(result.Content, 28)); |
| | | steProtocol.setYSpeed(melsecMcNet.getByteTransform().TransSingle(result.Content, 32)); |
| | | steProtocol.setZSpeed(melsecMcNet.getByteTransform().TransSingle(result.Content, 36)); |
| | | steProtocol.setXDistance(melsecMcNet.getByteTransform().TransSingle(result.Content, 40)); |
| | | steProtocol.setYDistance(melsecMcNet.getByteTransform().TransSingle(result.Content, 44)); |
| | | steProtocol.setXDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 48)); |
| | | steProtocol.setYDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 52)); |
| | | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | | // 复位信号 |
| | | if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) { |
| | | log.error("-------------------------------------------第一步、[堆垛机号:{}][工作号:{}]==>> 状态为90,等待确认!!",slave.getId(),crnProtocol.getTaskNo()); |
| | | if (steProtocol.getStatusType().equals(CrnStatusType.WAITING)) { |
| | | log.error("-------------------------------------------第一步、[堆垛机号:{}][工作号:{}]==>> 状态为90,等待确认!!",slave.getId(),steProtocol.getTaskNo()); |
| | | if (resetFlag) { |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setAckFinish((short)1); |
| | | if (write(crnCommand)) { |
| | | SteCommand steCommand = new SteCommand(); |
| | | steCommand.setAckFinish((short)1); |
| | | if (write(steCommand)) { |
| | | resetFlag = false; |
| | | } |
| | | } |
| | |
| | | // 根据实时信息更新数据库 |
| | | BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class); |
| | | BasCrnp basCrnp = new BasCrnp(); |
| | | basCrnp.setCrnErr(crnProtocol.getAlarm()==null?0:crnProtocol.getAlarm().longValue()); |
| | | basCrnp.setCrnErr(steProtocol.getAlarm()==null?0:steProtocol.getAlarm().longValue()); |
| | | basCrnp.setCrnNo(slave.getId()); |
| | | if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){ |
| | | if (!basCrnpService.updateById(steProtocol.toSqlModel(basCrnp))){ |
| | | log.error("堆垛机plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | |
| | |
| | | e.printStackTrace(); |
| | | 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()); |
| | | initCrn(); |
| | | initSte(); |
| | | } |
| | | |
| | | } |
| | |
| | | /** |
| | | * 写入数据 |
| | | */ |
| | | private boolean write(CrnCommand command){ |
| | | private boolean write(SteCommand command){ |
| | | if (null == command) { |
| | | log.error("堆垛机写入命令为空"); |
| | | return false; |
| | |
| | | /**************************************** 测试专用 *****************************************/ |
| | | /*****************************************************************************************/ |
| | | public static void main(String[] args) throws InterruptedException { |
| | | CrnSlave slave = new CrnSlave(); |
| | | slave.setId(1); |
| | | slave.setIp("192.168.3.39"); |
| | | slave.setPort(5015); |
| | | slave.setRack(0); |
| | | slave.setSlot(0); |
| | | SteThread melsecCrnThread = new SteThread(slave); |
| | | melsecCrnThread.connect(); |
| | | melsecCrnThread.readStatus(); |
| | | System.out.println(JSON.toJSONString(melsecCrnThread.crnProtocol)); |
| | | // CrnSlave slave = new CrnSlave(); |
| | | // slave.setId(1); |
| | | // slave.setIp("192.168.3.39"); |
| | | // slave.setPort(5015); |
| | | // slave.setRack(0); |
| | | // slave.setSlot(0); |
| | | // SteThread melsecCrnThread = new SteThread(slave); |
| | | // melsecCrnThread.connect(); |
| | | // melsecCrnThread.readStatus(); |
| | | // System.out.println(JSON.toJSONString(melsecCrnThread.crnProtocol)); |
| | | |
| | | // 1.入库 源和目标都发 |
| | | // CrnCommand command = new CrnCommand(); |