package com.mes.job;
|
|
import cn.hutool.json.JSONObject;
|
import com.mes.common.S7object;
|
import com.mes.device.PlcParameterObject;
|
import com.mes.md.entity.Tasking;
|
import com.mes.md.service.TaskingService;
|
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.ArrayList;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* @author SNG-010
|
*/
|
@Component
|
@Slf4j
|
public class PLCTurn {
|
|
PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
|
@Autowired
|
TaskingService taskingService;
|
//@Scheduled(fixedDelay = 500)
|
public void plcTurn() {
|
//清洗机速度
|
String rinseSpeed = plcParameterObject.getPlcParameter("rinseSpeed").getValue();
|
if(!Objects.equals(rinseSpeed, "")){
|
//给翻片台发送磨边机速度
|
S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("turnSpeed").getAddress(), Integer.parseInt(rinseSpeed));
|
}
|
|
}
|
//@Scheduled(fixedDelay = 1000)
|
public void turnWeb() {
|
//获取报警状态
|
String warning = plcParameterObject.getPlcParameter("turnWarning").getValue();
|
JSONObject jsonObject = new JSONObject();
|
if (!Objects.equals(warning, "0")) {
|
//log.info("报警信息:"+warning);
|
jsonObject.append("turnWarning", warning);
|
}
|
ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("turn");
|
if (sendwServer != null) {
|
for (WebSocketServer webserver : sendwServer) {
|
if (webserver != null) {
|
webserver.sendMessage(jsonObject.toString());
|
List<String> messages = webserver.getMessages();
|
if (!messages.isEmpty()) {
|
// // 将最后一个消息转换为整数类型的列表
|
webserver.clearMessages();
|
}
|
} else {
|
log.info("Home is closed");
|
}
|
}
|
|
}
|
}
|
|
}
|