New file |
| | |
| | | package com.mes.job; |
| | | |
| | | import cn.hutool.json.JSONObject; |
| | | import com.mes.common.S7object; |
| | | 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 PLCMechanicalArm { |
| | | |
| | | PlcParameterObject plcParameterObject =null; |
| | | @Autowired |
| | | TaskingService taskingService; |
| | | @Autowired |
| | | MachineMapper machineMapper; |
| | | // @Scheduled(fixedDelay = 500) |
| | | public void plcEdging() { |
| | | //机械臂请求信号 |
| | | String request = plcParameterObject.getPlcParameter("request").getValue(); |
| | | if (!Objects.equals(request, "")){ |
| | | //当机械臂请求信号为1的时候,//判断当前任务是定制还是标准 |
| | | String status = plcParameterObject.getPlcParameter("Status").getValue(); |
| | | boolean tasking = taskingService.insertTasking(status); |
| | | if(tasking){ |
| | | S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("overGlass").getAddress(), Integer.parseInt("1")); |
| | | //发送上片完毕 |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | //@Scheduled(fixedDelay = 1000) |
| | | public void mechanicalAmWeb() { |
| | | //获取当前任务表最新的一块任务状态 |
| | | //获取报警状态 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | // String warning = plcParameterObject.getPlcParameter("warning").getValue(); |
| | | // if (!Objects.equals(warning, "0")) { |
| | | // //log.info("报警信息:"+warning); |
| | | // jsonObject.append("warning", warning); |
| | | // } |
| | | Machine machine=machineMapper.selectById(1L); |
| | | List<Tasking> taskingList=taskingService.findMachineTask(machine); |
| | | jsonObject.append("taskingList", taskingList); |
| | | jsonObject.append("machine", machine); |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("mechanicalArm"); |
| | | 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"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |