package com.mes.common; import cn.hutool.json.JSONObject; import com.mes.downstorage.service.DownStorageCageService; import com.mes.downworkstation.service.DownWorkstationService; import com.mes.tools.WebSocketServer; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.List; @Component @Slf4j public class Plcdownglass { public static final String RESULT_IN = "1"; public static final String RESULT_OUT = "2"; public static final String RESULT_IN_OUT = "3"; @Autowired private DownStorageCageService downStorageCageService; @Autowired private DownWorkstationService downWorkstationService; @Scheduled(fixedDelay = 300) public void PlcdownglassTask() throws InterruptedException { JSONObject jsonObject = new JSONObject(); try { Thread.sleep(300); // String result = S7control.getinstance().ReadWord("DB14.0", 1).get(0) + ""; // String number = S7control.getinstance().ReadWord("DB14.2", 1).get(0) + ""; String result = "2"; String number = "1"; // 进片请求 if (RESULT_IN.equals(result)) { downStorageCageService.processInto(number); } // 出片请求 else if (RESULT_OUT.equals(result)) { downStorageCageService.processOut(); } // 进出片请求 else if (RESULT_IN_OUT.equals(result)) { // 先出后进 if (!downStorageCageService.processOut()) { downStorageCageService.processInto(number); } } //下片更新 downWorkstationService.insertdownglassinfo(); } catch (Exception e) { e.printStackTrace(); } } }