|  |  | 
 |  |  | import com.zy.asrs.wcs.rcs.News; | 
 |  |  | import com.zy.asrs.wcs.rcs.cache.OutputQueue; | 
 |  |  | import com.zy.asrs.wcs.rcs.entity.Device; | 
 |  |  | import com.zy.asrs.wcs.rcs.model.dto.WorkModeTypeDto; | 
 |  |  | import com.zy.asrs.wcs.rcs.model.enums.WorkModeType; | 
 |  |  | import com.zy.asrs.wcs.rcs.model.protocol.StaProtocol; | 
 |  |  | import com.zy.asrs.wcs.rcs.thread.DevpThread; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | 
 |  |  |      */ | 
 |  |  |     private int barcodeSize = 2; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 入出库模式 | 
 |  |  |      * 0:未知 | 
 |  |  |      * 1:入库启动中 | 
 |  |  |      * 2.入库模式 | 
 |  |  |      * 3.出库启动中 (不能生成入库工作档) | 
 |  |  |      * 4.出库模式 | 
 |  |  |      */ | 
 |  |  |     private Map<Integer, WorkModeTypeDto> workModeTypes = new ConcurrentHashMap<>(); | 
 |  |  |  | 
 |  |  |     public SuopaiSiemensDevpThread(Device device, RedisUtil redisUtil) { | 
 |  |  |         this.device = device; | 
 |  |  |         this.redisUtil = redisUtil; | 
 |  |  |  | 
 |  |  |         workModeTypes.put(101, new WorkModeTypeDto(101, WorkModeType.NONE, "DB1001.120")); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private ArrayList<BasConveyorSta> getStaNo() { | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void read() throws InterruptedException { | 
 |  |  |         updateWorkMode(); | 
 |  |  |         ArrayList<BasConveyorSta> staNos = getStaNo(); | 
 |  |  |         int staNoSize = staNos.size(); | 
 |  |  |         OperateResultExOne<byte[]> result = siemensS7Net.Read("DB1000.100", (short) (staNoSize*8)); | 
 |  |  |         OperateResultExOne<byte[]> result = siemensS7Net.Read("DB1000.100", (short) (staNoSize * 40)); | 
 |  |  |         if (result.IsSuccess) { | 
 |  |  |             for (int i = 0; i < staNoSize; i++) { | 
 |  |  |                 BasConveyorSta siteStation = staNos.get(i); | 
 |  |  | 
 |  |  |                     staProtocol.setSiteId(siteId); | 
 |  |  |                     station.put(siteId, staProtocol); | 
 |  |  |                 } | 
 |  |  |                 staProtocol.setStaNo( siemensS7Net.getByteTransform().TransInt16(result.Content, i*8 + 4 ));   // 目标站 | 
 |  |  |                 Thread.sleep(300); | 
 |  |  |                 staProtocol.setWorkNo((short) siemensS7Net.getByteTransform().TransInt32(result.Content, i * 8));     // 工作号 | 
 |  |  |  | 
 |  |  |                 boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, i*8+6, 2); | 
 |  |  |                 staProtocol.setAutoing(status[0]);  // 自动 | 
 |  |  |                 staProtocol.setLoading(status[1]);  // 有物 | 
 |  |  |                 staProtocol.setInEnable(status[2]); // 可入 | 
 |  |  |                 staProtocol.setOutEnable(status[3]);// 可出 | 
 |  |  |                 staProtocol.setEmptyMk(status[4]);  // 空板信号 | 
 |  |  |                 staProtocol.setFullPlt(status[5]);  // 满托盘 | 
 |  |  |                 staProtocol.setHigh(status[6]);     // 高库位 | 
 |  |  |                 staProtocol.setLow(status[7]);      // 低库位 | 
 |  |  |                 staProtocol.setWorkNo((short) siemensS7Net.getByteTransform().TransInt16(result.Content, i * 40 + 2));     // 工作号 | 
 |  |  |                 staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 40 + 4));   // 目标站 | 
 |  |  |                 staProtocol.setAutoing(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 40 + 6) == 2);  // 自动 | 
 |  |  |                 staProtocol.setLoading(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 40 + 32) == 1);  // 有物 | 
 |  |  |                 staProtocol.setInEnable(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 40 + 14) == 1); // 可入 | 
 |  |  |                 staProtocol.setOutEnable(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 40 + 14) == 2);// 可出 | 
 |  |  |                 staProtocol.setWorkMode((int) siemensS7Net.getByteTransform().TransInt16(result.Content, i * 40 + 8));// 工作模式 | 
 |  |  | //                staProtocol.setEmptyMk(status[4]);  // 空板信号 | 
 |  |  | //                staProtocol.setFullPlt(status[5]);  // 满托盘 | 
 |  |  | //                staProtocol.setHigh(status[6]);     // 高库位 | 
 |  |  | //                staProtocol.setLow(status[7]);      // 低库位 | 
 |  |  |  | 
 |  |  |                 if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { | 
 |  |  |                     staProtocol.setPakMk(true); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Thread.sleep(200); | 
 |  |  |         ArrayList<BasConveyorSta> errorStaNo = getStaNo(); | 
 |  |  |         OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB101.800.0", (short) (errorStaNo.size() * 4)); | 
 |  |  |         if (result3.IsSuccess) { | 
 |  |  |             for (int i = 0; i < errorStaNo.size(); i++) { | 
 |  |  |                 BasConveyorSta siteStation = errorStaNo.get(i); | 
 |  |  |                 Integer siteId = siteStation.getSiteNo(); // 站点编号 | 
 |  |  |                 StaProtocol staProtocol = station.get(siteId); | 
 |  |  |                 boolean[] status = siemensS7Net.getByteTransform().TransBool(result3.Content, (i * 4 + 2), 2); | 
 |  |  |                 staProtocol.setFrontErr(status[0]);//前超限 | 
 |  |  |                 staProtocol.setBackErr(status[1]);//后超限 | 
 |  |  |                 staProtocol.setHighErr(status[2]);//超高 | 
 |  |  |                 staProtocol.setLeftErr(status[3]);//左超限 | 
 |  |  |                 staProtocol.setRightErr(status[4]);//右超限 | 
 |  |  |                 staProtocol.setWeightErr(status[5]);//超重 | 
 |  |  |                 staProtocol.setBarcodeErr(status[6]);//扫码失败 | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  | 
 |  |  |             staProtocol.setPakMk(pakMk); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void updateWorkMode() { | 
 |  |  |         for (Map.Entry<Integer, WorkModeTypeDto> entry : workModeTypes.entrySet()) { | 
 |  |  |             WorkModeTypeDto workModeTypeDto = entry.getValue(); | 
 |  |  |             WorkModeType workModeType = workModeTypeDto.getWorkModeType(); | 
 |  |  |             if (workModeType != WorkModeType.NONE) { | 
 |  |  |                 if (!siemensS7Net.Write(workModeTypeDto.getAddress(), workModeType.id).IsSuccess) { | 
 |  |  |                     OutputQueue.DEVP.offer(MessageFormat.format("写入输送线{1}入出库模式失败。输送线编号={0}", device.getId(), workModeTypeDto.getSiteId())); | 
 |  |  |                     log.error("写入输送线{1}入出库模式失败。输送线编号={0}", device.getId(), workModeTypeDto.getSiteId()); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public boolean switchWorkMode(int siteId, int workMode) { | 
 |  |  |         WorkModeTypeDto workModeTypeDto = workModeTypes.get(siteId); | 
 |  |  |         if(workModeTypeDto == null) { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         workModeTypeDto.setWorkModeType(WorkModeType.get((short) workMode)); | 
 |  |  |         workModeTypes.put(siteId, workModeTypeDto); | 
 |  |  |         return true; | 
 |  |  |     } | 
 |  |  | } |