| | |
| | | package com.mes.job; |
| | | |
| | | import cn.hutool.json.JSONObject; |
| | | import com.mes.common.S7object; |
| | | import com.mes.device.PlcParameterObject; |
| | | import com.mes.engineering.entity.Engineering; |
| | | import com.mes.engineering.service.EngineeringService; |
| | | import com.mes.uppattenusage.entity.UpPattenUsage; |
| | | import com.mes.uppattenusage.service.UpPattenUsageService; |
| | | import com.mes.workstation.entity.UpWorkstation; |
| | | import com.mes.workstation.service.UpWorkstationService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * @author SNG-010 |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class PlcLoadGlassTask { |
| | | |
| | | @Autowired |
| | | private UpWorkstationService upWorkstationService; |
| | | @Autowired |
| | | private EngineeringService engineeringService; |
| | | @Autowired |
| | | private UpPattenUsageService upPattenUsageService; |
| | | |
| | | PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject; |
| | | |
| | | /** |
| | | * fixedRate : 上一个调用开始后再次调用的延时(不用等待上一次调用完成) |
| | | * fixedDelay : 上一个调用结束后再次调用的延时 |
| | | */ |
| | | |
| | | @Scheduled(fixedDelay = 300) |
| | | public void plcLoadGlassTask() throws InterruptedException { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | try { |
| | | Thread.sleep(300); |
| | | upWorkstationService.selectPriority(); |
| | | //获取是否有上片请求 |
| | | String loadRequest = plcParameterObject.getPlcParameter("loadRequest").getValue(); |
| | | String mesToPlc = plcParameterObject.getPlcParameter("MesToPlc").getValue(); |
| | | //判断开始上片的工程号 |
| | | Engineering engineering = engineeringService.selectInitiate(1); |
| | | if ("1".equals(loadRequest) && engineering != null) { |
| | | log.info("开始上片任务"); |
| | | UpPattenUsage upPattenUsage = upWorkstationService.selectPriority(engineering); |
| | | log.info("当有请求时查询当前上片顺序的玻璃信息{}", upPattenUsage); |
| | | UpWorkstation upwork = upWorkstationService.selectWorkstation(upPattenUsage); |
| | | log.info("符合的尺寸的工位玻璃:{}", upwork); |
| | | if (upwork != null) { |
| | | int workId = upwork.getWorkstationId();//工位id |
| | | double width = upwork.getPatternWidth();//宽度 |
| | | double height = upwork.getPatternHeight();//高度 |
| | | S7object.getinstance().plccontrol.WriteWord(plcParameterObject.getPlcParameter("WorkId").getAddress(), (short) workId); |
| | | S7object.getinstance().plccontrol.WriteWord(plcParameterObject.getPlcParameter("GlassWidth").getAddress(), (short) width); |
| | | S7object.getinstance().plccontrol.WriteWord(plcParameterObject.getPlcParameter("GlassHeight").getAddress(), (short) height); |
| | | S7object.getinstance().plccontrol.WriteWord(plcParameterObject.getPlcParameter("MesToPlc").getAddress(), (short) 1); |
| | | //更改上片表状态 |
| | | upPattenUsageService.updateUpPattenUsageState(upPattenUsage, workId); |
| | | |
| | | } |
| | | } |
| | | if ("1".equals(mesToPlc) && "0".equals(loadRequest)) { |
| | | //请求字为零时,任务字清零 |
| | | S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("MesToPlc").getAddress(), 0); |
| | | } |
| | | //执行后休眠300毫秒 |
| | | //Thread.sleep(300); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 300) |
| | | public void plcLoadGlassReport() { |
| | | //获取是否有汇报 |
| | | String loadStatus = plcParameterObject.getPlcParameter("PlcStatus").getValue(); |
| | | if (loadStatus != null) { |
| | | log.info(loadStatus); |
| | | switch (loadStatus) { |
| | | case "1": |
| | | log.info("收到汇报任务完成"); |
| | | S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("MesToPlcStatus").getAddress(), 1); |
| | | break; |
| | | case "2": |
| | | log.info("收到汇报未完成任务"); |
| | | //减少工位数量,恢复任务状态 |
| | | overTask(loadStatus, 0); |
| | | break; |
| | | case "3": |
| | | log.info("收到汇报玻璃破损"); |
| | | overTask(loadStatus, 0); |
| | | break; |
| | | case "0": |
| | | log.info("收到汇报清0状态"); |
| | | //减少工位数量,完成任务状态 |
| | | overTask(loadStatus, 100); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void overTask(String loadStatus, int state) { |
| | | UpPattenUsage upPattenUsage = upPattenUsageService.selectOverTask(); |
| | | if (upPattenUsage != null) { |
| | | log.info("收到汇报清{}状态", loadStatus); |
| | | //减少工位数量 |
| | | upWorkstationService.reduceWorkstationNumber(upPattenUsage.getState()); |
| | | //完成上片表状态 |
| | | upPattenUsageService.updateUpPattenUsageState(upPattenUsage, state); |
| | | S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("MesToPlcStatus").getAddress(), 0); |
| | | } |
| | | } |
| | | |
| | | } |