New file |
| | |
| | | package com.mes.job; |
| | | |
| | | import cn.hutool.json.JSONObject; |
| | | import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType; |
| | | import com.mes.common.S7object; |
| | | import com.mes.common.S7objectCleaning; |
| | | import com.mes.common.S7objectMachine; |
| | | import com.mes.common.S7objectMarking; |
| | | import com.mes.device.PlcParameterInfo; |
| | | import com.mes.device.PlcParameterObject; |
| | | import com.mes.md.entity.Machine; |
| | | import com.mes.md.entity.Tasking; |
| | | import com.mes.md.mapper.MachineMapper; |
| | | 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 PLCCleaning { |
| | | |
| | | PlcParameterObject plcParameterObject =null; |
| | | @Autowired |
| | | TaskingService taskingService; |
| | | @Autowired |
| | | MachineMapper machineMapper; |
| | | public S7objectMachine s7objectMachine; |
| | | |
| | | //@Scheduled(fixedDelay = 500) |
| | | public void cleaning() { |
| | | //磨边线速度 10.36.164.200 |
| | | Long machineId=8L; |
| | | Machine machine=machineMapper.selectById(machineId); |
| | | if (s7objectMachine==null){ |
| | | s7objectMachine=new S7objectMachine(machine.getIp(),machine.getPort(),"PlcCleaning", EPlcType.S200_SMART); |
| | | s7objectMachine.start(); |
| | | } |
| | | PlcParameterObject plcParameterObject = s7objectMachine.PlcMesObject; |
| | | PlcParameterInfo edgSpeed =plcParameterObject.getPlcParameter("edgSpeed");//磨边机速度 |
| | | PlcParameterInfo thinness =plcParameterObject.getPlcParameter("thinness");//厚度 |
| | | if (machine.getIsLog()>0){ |
| | | s7objectMachine.consoleLogInfo(); |
| | | } |
| | | int edgSpeedInt=0; |
| | | int edgThinnessInt=0; |
| | | if(!(edgSpeedInt+"").equals(edgSpeed.getValue())||!(edgThinnessInt+"").equals(thinness.getValue())){ |
| | | //给清洗机器发送磨边机速度 |
| | | S7objectCleaning.getinstance().plccontrol.writeWord(edgSpeed.getAddress(), edgSpeedInt); |
| | | S7objectCleaning.getinstance().plccontrol.writeWord(thinness.getAddress(), edgThinnessInt); |
| | | } |
| | | } |
| | | //@Scheduled(fixedDelay = 1000) |
| | | public void cleaningTask() { |
| | | //获取报警状态 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | Machine machine=machineMapper.selectById(7L); |
| | | List<Tasking> taskingList=taskingService.findMachineTask(machine); |
| | | jsonObject.append("taskingList", taskingList); |
| | | jsonObject.append("machine", machine); |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("cleaning"); |
| | | if (sendwServer != null) { |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | if (webserver != null) { |
| | | try { |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | List<String> messages = webserver.getMessages(); |
| | | if (!messages.isEmpty()) { |
| | | // // 将最后一个消息转换为整数类型的列表 |
| | | webserver.clearMessages(); |
| | | } |
| | | }catch (Exception e) { |
| | | |
| | | } |
| | | } else { |
| | | log.info("Home is closed"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |