| | |
| | | import com.mes.md.mapper.TaskingMapper; |
| | | import com.mes.md.mapper.WorkTaskDetailMapper; |
| | | import com.mes.md.service.TaskingService; |
| | | import com.mes.service.ModbusTcp; |
| | | import com.mes.service.PlcAgreement; |
| | | import com.mes.service.PlcParameter; |
| | | import com.mes.tools.WebSocketServer; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | |
| | | public void plcMarkingTask(Long machineId) { |
| | | Machine machine=machineMapper.selectById(machineId); |
| | | PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject; |
| | | String taskRequestTypeValue = plcParameterObject.getPlcParameter("A06_request_word").getValue(); |
| | | String glassIdeValue = plcParameterObject.getPlcParameter("A05_scanning_ID").getValue(); |
| | | String confirmationWrodValue = plcParameterObject.getPlcParameter("MES_confirmation_word").getValue(); |
| | | String confirmationWrodAddress = plcParameterObject.getPlcParameter("MES_confirmation_word").getAddress(); |
| | | String currentSlot = plcParameterObject.getPlcParameter("Current_slot").getValue(); |
| | | if ("0".equals(taskRequestTypeValue)) { |
| | | if ("0".equals(confirmationWrodValue)) { |
| | | ModbusTcp modbusTcp =new ModbusTcp(machine.getIp(),machine.getPort()); |
| | | PlcAgreement plcAgreement=modbusTcp.getPlcAgreement("DB14.0"); |
| | | PlcParameter plcRequest =plcAgreement.getPlcParameter(0);//请求字 |
| | | PlcParameter plcRequestID =plcAgreement.getPlcParameter(1);//请求ID |
| | | PlcParameter mesSend =plcAgreement.getPlcParameter(10);//发送字 |
| | | PlcParameter mesSendID =plcAgreement.getPlcParameter(11);//发送ID |
| | | |
| | | PlcParameter plcReport =plcAgreement.getPlcParameter(0);//汇报字 |
| | | PlcParameter plcReportID =plcAgreement.getPlcParameter(1);//汇报ID |
| | | PlcParameter mesConfirm =plcAgreement.getPlcParameter(10);//确认字 |
| | | PlcParameter mesConfirmID =plcAgreement.getPlcParameter(11);//确认ID |
| | | plcRequest.getReadValue(); |
| | | if ("0".equals(plcRequest.getReadValue())) { |
| | | if ("0".equals(mesSend.getReadValue())) { |
| | | log.info("2、获取到的请求字为0,且发送字为0,不执行任务"); |
| | | return; |
| | | } |
| | | log.info("2、获取到的请求字为0,将发送字改为0"); |
| | | S7object.getinstance().plccontrol.writeWord(confirmationWrodAddress, 0); |
| | | mesSend.setWriteValue("0"); |
| | | modbusTcp.write(mesSend);//向PLC发送 |
| | | return; |
| | | } |
| | | if (!"0".equals(confirmationWrodValue)) { |
| | | if (!"0".equals(mesSend.getReadValue())) { |
| | | log.info("2、获取到的请求字不为0,将发送字不为0,直接结束"); |
| | | return; |
| | | } |
| | | if ("1".equals(taskRequestTypeValue)) { |
| | | log.info("2、进片请求,且发送字为0,执行打标任务"); |
| | | plcRequest(glassIdeValue, confirmationWrodAddress, currentSlot,machine); |
| | | }else if ("3".equals(taskRequestTypeValue)) { |
| | | log.info("2、完成请求,执行完成任务"); |
| | | plcReport(glassIdeValue, confirmationWrodAddress, currentSlot,machine); |
| | | if ("1".equals(mesConfirm.getReadValue())&&"0".equals(mesConfirm.getReadValue())) { |
| | | log.info("2、汇报请求,且确认字为0,完成打标任务"); |
| | | plcReport(mesConfirm,machine); |
| | | }else if ("1".equals(plcRequest.getReadValue())) { |
| | | log.info("2、任务请求,执行发送任务"); |
| | | plcRequest(mesSend,machine); |
| | | } |
| | | } |
| | | public void plcRequest(String glassIdeValue, String confirmationWrodAddress, String currentSlot, Machine machine) { |
| | | public void plcRequest(PlcParameter mesSend, Machine machine) { |
| | | //查找打标机任务 |
| | | Tasking tasking=taskingService.startMachineTask(machine); |
| | | if(tasking!=null&&"开工".equals(machine.getState())){//有任务 |
| | |
| | | } |
| | | |
| | | } |
| | | public void plcReport(String glassIdeValue, String confirmationWrodAddress, String currentSlot, Machine machine) { |
| | | public void plcReport(PlcParameter mesConfirm, Machine machine) { |
| | | //查找打标机工作的任务 |
| | | //查找打标机任务 |
| | | int finishCount=taskingService.finishMachineTask(machine); |
| | | if(finishCount>0){//数据已标记完成 |
| | | log.info("正常汇报:"); |
| | | |
| | | }else{ |
| | | log.info("当前无共工作的任务,无效汇报完成!"); |
| | | } |
| | | } |
| | | //@Scheduled(fixedDelay = 1000) |
| | | @Scheduled(fixedDelay = 1000) |
| | | public void markingTasks() { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | Machine machine=machineMapper.selectById(11L); |
| | | List<Tasking> taskingList=taskingService.findMachineTask(machine); |
| | | jsonObject.append("taskingList", taskingList); |
| | | |
| | | jsonObject.append("machine", machine); |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("marking"); |
| | | if (sendwServer != null) { |
| | | for (WebSocketServer webserver : sendwServer) { |