|  |  | 
 |  |  | import com.core.common.SpringUtils; | 
 |  |  | import com.zy.asrs.entity.BasCrnOpt; | 
 |  |  | import com.zy.asrs.entity.BasCrnp; | 
 |  |  | import com.zy.asrs.entity.DeviceDataLog; | 
 |  |  | import com.zy.asrs.service.BasCrnOptService; | 
 |  |  | import com.zy.asrs.service.BasCrnpService; | 
 |  |  | import com.zy.asrs.service.DeviceDataLogService; | 
 |  |  | import com.zy.common.utils.News; | 
 |  |  | import com.zy.core.CrnThread; | 
 |  |  | import com.zy.core.cache.MessageQueue; | 
 |  |  | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  |  | 
 |  |  | import java.text.MessageFormat; | 
 |  |  | import java.util.Base64; | 
 |  |  | import java.util.Date; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  | 
 |  |  |      */ | 
 |  |  |     private void readStatus(){ | 
 |  |  |         try { | 
 |  |  |             OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 56); | 
 |  |  |             short len = 56; | 
 |  |  |             if (slave.getId() == 1) { | 
 |  |  |                 len = 58; | 
 |  |  |             } | 
 |  |  |             OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", len); | 
 |  |  |             if (result.IsSuccess) { | 
 |  |  |                 if (null == crnProtocol) { | 
 |  |  |                     crnProtocol = new CrnProtocol(); | 
 |  |  | 
 |  |  |                 crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 44)); | 
 |  |  |                 crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48)); | 
 |  |  |                 crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 52)); | 
 |  |  |                 if (slave.getId() == 1) { | 
 |  |  |                     crnProtocol.setCrnLane((int) siemensNet.getByteTransform().TransInt16(result.Content, 56)); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); | 
 |  |  |  | 
 |  |  | 
 |  |  |                             resetFlag = false; | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 if (System.currentTimeMillis() - crnProtocol.getDeviceDataLog() > 1000 * 5) { | 
 |  |  |                     //采集时间超过5s,保存一次数据记录 | 
 |  |  |                     //保存数据记录 | 
 |  |  |                     DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class); | 
 |  |  |                     DeviceDataLog deviceDataLog = new DeviceDataLog(); | 
 |  |  |                     deviceDataLog.setOriginData(Base64.getEncoder().encodeToString(result.Content)); | 
 |  |  |                     deviceDataLog.setWcsData(JSON.toJSONString(crnProtocol)); | 
 |  |  |                     deviceDataLog.setType("crn"); | 
 |  |  |                     deviceDataLog.setDeviceNo(crnProtocol.getCrnNo()); | 
 |  |  |                     deviceDataLog.setCreateTime(new Date()); | 
 |  |  |                     deviceDataLogService.insert(deviceDataLog); | 
 |  |  |  | 
 |  |  |                     //更新采集时间 | 
 |  |  |                     crnProtocol.setDeviceDataLog(System.currentTimeMillis()); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 try { | 
 |  |  | 
 |  |  | //        array[9] = command.getSourceStaNo(); | 
 |  |  | //        array[10] = command.getDestinationStaNo(); | 
 |  |  |         array[9] = command.getCommand(); | 
 |  |  |         OperateResult result = siemensNet.Write("DB100.0", array); | 
 |  |  |  | 
 |  |  |         OperateResult result = null; | 
 |  |  |         int idx = 0; | 
 |  |  |         do { | 
 |  |  |             OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20); | 
 |  |  |             if (resultRead.IsSuccess) { | 
 |  |  |                 if (command.getAckFinish() == 0) { | 
 |  |  |                     short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2); | 
 |  |  |                     short taskMode = siemensNet.getByteTransform().TransInt16(resultRead.Content, 4); | 
 |  |  |                     short sourcePosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 6); | 
 |  |  |                     short sourcePosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 8); | 
 |  |  |                     short sourcePosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 10); | 
 |  |  |                     short destinationPosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 12); | 
 |  |  |                     short destinationPosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 14); | 
 |  |  |                     short destinationPosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 16); | 
 |  |  |                     if(taskNo == 0 || taskMode == 0 || sourcePosX == 0 || sourcePosY == 0 || sourcePosZ == 0 || destinationPosX == 0 || destinationPosY == 0 || destinationPosZ == 0) { | 
 |  |  |                         result = siemensNet.Write("DB100.0", array); | 
 |  |  |                     }else { | 
 |  |  |                         break; | 
 |  |  |                     } | 
 |  |  |                 }else { | 
 |  |  |                     short ackFinish = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0); | 
 |  |  |                     if(ackFinish != command.getAckFinish()) { | 
 |  |  |                         result = siemensNet.Write("DB100.0", array); | 
 |  |  |                     }else { | 
 |  |  |                         break; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             idx++; | 
 |  |  |             Thread.sleep(500L); | 
 |  |  |         } while (idx < 5); | 
 |  |  |  | 
 |  |  |         if (command.getAckFinish() == 0) { | 
 |  |  |             short commandFinish = 1; | 
 |  |  |             Thread.sleep(100L); | 
 |  |  |             result = siemensNet.Write("DB100.18", commandFinish); | 
 |  |  |             int i = 0; | 
 |  |  |             do { | 
 |  |  |                 OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 4); | 
 |  |  |                 OperateResultExOne<byte[]> resultReadConfirm = siemensNet.Read("DB100.18", (short) 2); | 
 |  |  |                 if (resultRead.IsSuccess && resultReadConfirm.IsSuccess) { | 
 |  |  |                     short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2); | 
 |  |  |                     short confirm = siemensNet.getByteTransform().TransInt16(resultReadConfirm.Content, 0); | 
 |  |  |                     if(taskNo != 0 && confirm == 0) { | 
 |  |  |                         result = siemensNet.Write("DB100.18", commandFinish); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |                 i++; | 
 |  |  |                 Thread.sleep(500L); | 
 |  |  |             } while (i < 5); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         this.crnProtocol.setLastCommandTime(System.currentTimeMillis()); | 
 |  |  |         try { | 
 |  |  |             // 日志记录 | 
 |  |  |             BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class); | 
 |  |  | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void close() { |