| | |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | public class MachineLamination extends Thread{ |
| | | public class MachineLamination extends Thread { |
| | | |
| | | |
| | | private MachineMapper machineMapper; |
| | | private TaskingService taskingService; |
| | | private S7objectMachine s7objectMachine; |
| | | public Machine thisMachine; |
| | | public MachineLamination(Machine machine, MachineMapper machineMapper, TaskingService taskingService){ |
| | | |
| | | public MachineLamination(Machine machine, MachineMapper machineMapper, TaskingService taskingService) { |
| | | this.thisMachine = machine; |
| | | this.machineMapper = machineMapper; |
| | | this.taskingService = taskingService; |
| | | } |
| | | |
| | | public void plcStart() { |
| | | Machine machine=machineMapper.selectById(thisMachine.getId()); |
| | | if (s7objectMachine==null){ |
| | | s7objectMachine=new S7objectMachine(machine.getIp(),machine.getPort(),machine.getFileName(), EPlcType.S1200); |
| | | s7objectMachine.start(); |
| | | } |
| | | PlcParameterObject plcParameterObject = s7objectMachine.PlcMesObject; |
| | | PlcParameterInfo plcRequest =plcParameterObject.getPlcParameter("plcRequest");//请求字 |
| | | PlcParameterInfo mesSend =plcParameterObject.getPlcParameter("mesSend");//发送字 |
| | | PlcParameterInfo lengthOutOfService =plcParameterObject.getPlcParameter("length");//长 |
| | | PlcParameterInfo widthOutOfService =plcParameterObject.getPlcParameter("width");//宽 |
| | | PlcParameterInfo markingMode =plcParameterObject.getPlcParameter("thickness");//厚度 |
| | | public void plcStart()throws Exception { |
| | | Machine machine = machineMapper.selectById(thisMachine.getId()); |
| | | |
| | | PlcParameterInfo plcReport =plcParameterObject.getPlcParameter("plcReport");//汇报字 |
| | | PlcParameterInfo mesConfirm =plcParameterObject.getPlcParameter("mesConfirm");//确认字 |
| | | PlcParameterInfo mesConfirmID =plcParameterObject.getPlcParameter("mesConfirmID");//确认ID |
| | | if (machine.getIsLog()>0){ |
| | | S7objectMachine s7objectMachine = new S7objectMachine(machine.getIp(), machine.getPort(), machine.getFileName(), EPlcType.S1200); |
| | | s7objectMachine.readData();//按照json文件读取内容 |
| | | PlcParameterObject plcParameterObject = s7objectMachine.PlcMesObject; |
| | | if (plcParameterObject == null) { |
| | | s7objectMachine.plccontrol.closeS7client(); |
| | | return; |
| | | } |
| | | try { |
| | | PlcParameterInfo plcRequest = plcParameterObject.getPlcParameter("plcRequest");//请求字 |
| | | PlcParameterInfo mesSend = plcParameterObject.getPlcParameter("mesSend");//发送字 |
| | | PlcParameterInfo lengthOutOfService = plcParameterObject.getPlcParameter("length");//长 |
| | | PlcParameterInfo widthOutOfService = plcParameterObject.getPlcParameter("width");//宽 |
| | | PlcParameterInfo markingMode = plcParameterObject.getPlcParameter("thickness");//厚度 |
| | | |
| | | PlcParameterInfo plcReport = plcParameterObject.getPlcParameter("plcReport");//汇报字 |
| | | PlcParameterInfo mesConfirm = plcParameterObject.getPlcParameter("mesConfirm");//确认字 |
| | | PlcParameterInfo mesConfirmID = plcParameterObject.getPlcParameter("mesConfirmID");//确认ID |
| | | if (machine.getIsLog() > 0) { |
| | | s7objectMachine.consoleLogInfo(); |
| | | } |
| | | if ("0".equals(plcRequest.getValue())&&"1".equals(mesSend.getValue())) { |
| | | if ("0".equals(plcRequest.getValue()) && "1".equals(mesSend.getValue())) { |
| | | //发送字置0 |
| | | log.info("1.发送字置零,清除上次发送的数据{}",mesSend.getValue()); |
| | | log.info("1.发送字置零,清除上次发送的数据{}", mesSend.getValue()); |
| | | s7objectMachine.plccontrol.writeWord(mesSend.getAddress(), 0); |
| | | return; |
| | | } |
| | | if ("0".equals(plcReport.getValue())&&"1".equals(mesConfirm.getValue())) { |
| | | if ("0".equals(plcReport.getValue()) && "1".equals(mesConfirm.getValue())) { |
| | | log.info("2.确认字置零"); |
| | | //发送字置0 |
| | | s7objectMachine.plccontrol.writeWord(mesConfirm.getAddress(), 0); |
| | | return; |
| | | } |
| | | if("1".equals(plcReport.getValue())&&"0".equals(mesConfirm.getValue())){ |
| | | |
| | | |
| | | int finishCount=taskingService.finishMachineTask(machine); |
| | | if ("1".equals(plcReport.getValue()) && "0".equals(mesConfirm.getValue())) { |
| | | int finishCount = taskingService.finishMachineTask(machine); |
| | | log.info("3、任务完成"); |
| | | if(finishCount>0){//有任务 |
| | | if (finishCount > 0) {//有任务 |
| | | s7objectMachine.plccontrol.writeWord(mesConfirm.getAddress(), 1); |
| | | return; |
| | | } |
| | | return; |
| | | } |
| | | List<Tasking> taskingCount=taskingService.findMachineWorkStateTask(machine,"正在工作"); |
| | | if("1".equals(plcRequest.getValue())&&"0".equals(mesSend.getValue()) |
| | | &&"开工".equals(machine.getState()) |
| | | &&taskingCount.size()<machine.getMaxTaskCount()){ |
| | | List<Tasking> taskingCount = taskingService.findMachineWorkStateTask(machine, "正在工作"); |
| | | if ("1".equals(plcRequest.getValue()) && "0".equals(mesSend.getValue()) |
| | | && "开工".equals(machine.getState()) |
| | | && taskingCount.size() < machine.getMaxTaskCount()) { |
| | | |
| | | Tasking tasking=taskingService.startMachineTask(machine); |
| | | if(tasking!=null){ |
| | | log.info("4、发送数据:{},{},{}",tasking.getLength().intValue(),tasking.getWidth().intValue(),1); |
| | | Tasking tasking = taskingService.startMachineTask(machine); |
| | | if (tasking != null) { |
| | | log.info("4、发送数据:{},{},{}", tasking.getLength().intValue(), tasking.getWidth().intValue(), 1); |
| | | s7objectMachine.plccontrol.writeWord(lengthOutOfService.getAddress(), tasking.getLength().intValue());//x |
| | | s7objectMachine.plccontrol.writeWord(widthOutOfService.getAddress(), tasking.getWidth().intValue());//y |
| | | |
| | |
| | | return; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | s7objectMachine.plccontrol.closeS7client(); |
| | | log.info("逻辑处理异常:设备id【{}】", machine.getId()); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | while (this != null) { |
| | | while (true) { |
| | | try { |
| | | Thread.sleep(1000); |
| | | plcStart(); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } catch (Exception e) { |
| | | log.info("{}", e.getMessage()); |
| | | } |
| | | } |
| | | } |