| | |
| | | */ |
| | | private void readStatus(){ |
| | | try { |
| | | if (null == crnProtocol) { |
| | | crnProtocol = new CrnProtocol(); |
| | | } |
| | | |
| | | /* 方法1 */ |
| | | OperateResultExOne<byte[]> result = melsecMcNet.Read("D2231", (short) 62); |
| | | if (result.IsSuccess) { |
| | | if (null == crnProtocol) { |
| | | crnProtocol = new CrnProtocol(); |
| | | } |
| | | crnProtocol.setMode(melsecMcNet.getByteTransform().TransInt16(result.Content, 0)); |
| | | crnProtocol.setTaskNo(melsecMcNet.getByteTransform().TransInt16(result.Content, 4)); |
| | | crnProtocol.setStatus(melsecMcNet.getByteTransform().TransInt16(result.Content, 6)); |
| | |
| | | crnProtocol.setYDistance(melsecMcNet.getByteTransform().TransSingle(result.Content, 50)); |
| | | crnProtocol.setXDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 54)); |
| | | crnProtocol.setYDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 58)); |
| | | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | | // 复位信号 |
| | | if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) { |
| | | if (resetFlag) { |
| | | if (melsecMcNet.Write("D2218", (short) 1).IsSuccess) { |
| | | resetFlag = false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 根据实时信息更新数据库 |
| | | BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class); |
| | | BasCrnp basCrnp = new BasCrnp(); |
| | | basCrnp.setCrnNo(slave.getId()); |
| | | if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){ |
| | | log.error("堆垛机plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | |
| | | } else { |
| | | throw new CoolException("堆垛机plc状态信息失败"); |
| | |
| | | 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()); |
| | | return; |
| | | } |
| | | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | | // 复位信号 |
| | | if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) { |
| | | if (resetFlag) { |
| | | if (melsecMcNet.Write("D2218", (short) 1).IsSuccess) { |
| | | resetFlag = false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 根据实时信息更新数据库 |
| | | // BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class); |
| | | // BasCrnp basCrnp = new BasCrnp(); |
| | | // basCrnp.setCrnNo(slave.getId()); |
| | | // if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){ |
| | | // log.error("堆垛机plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | // } |
| | | |
| | | } |
| | | |