| | |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | public class MachineFlipSlice extends Thread{ |
| | | public class MachineFlipSlice extends Thread { |
| | | |
| | | |
| | | private MachineMapper machineMapper; |
| | | private TaskingService taskingService; |
| | | private S7objectMachine s7objectMachine; |
| | | public static int thinness = 40; |
| | | public static int edgSpeed = 40; |
| | | //public static Long machineId = 6L; |
| | | public List<Map> sendRecords = new ArrayList<>(); |
| | | public Machine thisMachine; |
| | | |
| | | public MachineFlipSlice(Machine machine,MachineMapper machineMapper, TaskingService taskingService){ |
| | | public MachineFlipSlice(Machine machine, MachineMapper machineMapper, TaskingService taskingService) { |
| | | this.thisMachine = machine; |
| | | this.machineMapper = machineMapper; |
| | | this.taskingService = taskingService; |
| | | } |
| | | |
| | | public void plcStart() { |
| | | //Long machineId=26L; |
| | | Machine machine=machineMapper.selectById(thisMachine.getId()); |
| | | if (s7objectMachine==null){ |
| | | s7objectMachine=new S7objectMachine(machine.getIp(),machine.getPort(),machine.getFileName(), EPlcType.S1200); |
| | | s7objectMachine.start(); |
| | | } |
| | | public void plcStart() throws Exception { |
| | | Machine machine = machineMapper.selectById(thisMachine.getId()); |
| | | S7objectMachine s7objectMachine = new S7objectMachine(machine.getIp(), machine.getPort(), machine.getFileName(), EPlcType.S1200); |
| | | s7objectMachine.readData();//按照json文件读取内容 |
| | | PlcParameterObject plcParameterObject = s7objectMachine.PlcMesObject; |
| | | PlcParameterInfo plcRequest =plcParameterObject.getPlcParameter("plcRequest");//请求字 |
| | | PlcParameterInfo plcRequestID =plcParameterObject.getPlcParameter("plcRequestID");//请求ID |
| | | PlcParameterInfo plcRequestType =plcParameterObject.getPlcParameter("plcRequestType");//PLC请求 |
| | | |
| | | PlcParameterInfo mesSend =plcParameterObject.getPlcParameter("mesSend");//发送字 |
| | | PlcParameterInfo mesSendId =plcParameterObject.getPlcParameter("mesSendID");//发送ID |
| | | PlcParameterInfo length =plcParameterObject.getPlcParameter("length");//长 |
| | | PlcParameterInfo width =plcParameterObject.getPlcParameter("width");//宽 |
| | | PlcParameterInfo mesSendType =plcParameterObject.getPlcParameter("mesSendType");// 扫码1 不扫码2 |
| | | |
| | | String scan_id=""; |
| | | if (machine.getIsLog()>0){ |
| | | s7objectMachine.consoleLogInfo(); |
| | | } |
| | | if ("0".equals(plcRequestType.getValue())&&!"0".equals(mesSendType.getValue())) { |
| | | //发送字置0 |
| | | log.info("1.发送类型字置零,清除上次发送的类型数据{}->0",mesSendType.getValue()); |
| | | s7objectMachine.plccontrol.writeWord(mesSendType.getAddress(), 0); |
| | | |
| | | if (plcParameterObject == null) { |
| | | s7objectMachine.plccontrol.closeS7client(); |
| | | return; |
| | | } |
| | | if ("0".equals(plcRequest.getValue())&&!"0".equals(mesSend.getValue())) { |
| | | //发送字置0 |
| | | int finishCount=taskingService.finishMachineTask(machine); |
| | | nullMachine(machine); |
| | | log.info("2.发送字置零,清除上次发送的数据{},{},{},{},{}" |
| | | ,finishCount |
| | | ,length.getValue() |
| | | ,width.getValue() |
| | | ,mesSendId.getValue() |
| | | ,mesSend.getValue()); |
| | | s7objectMachine.plccontrol.writeWord(length.getAddress(), 0); |
| | | s7objectMachine.plccontrol.writeWord(width.getAddress(), 0); |
| | | s7objectMachine.plccontrol.writeWord(mesSendId.getAddress(), 0); |
| | | s7objectMachine.plccontrol.writeWord(mesSend.getAddress(), 0); |
| | | return; |
| | | } |
| | | if ("1".equals(plcRequestType.getValue())&&"0".equals(mesSendType.getValue())) { |
| | | //发送类型 1扫码 2不扫码 |
| | | int type=machine.getMode()==1?2:1; |
| | | log.info("3.发送类型数据0->{}",mesSendType.getValue()); |
| | | s7objectMachine.plccontrol.writeWord(mesSendType.getAddress(), type); |
| | | return; |
| | | } |
| | | List<Tasking> taskingCount=taskingService.findMachineWorkStateTask(machine,"正在工作"); |
| | | if(("1".equals(plcRequest.getValue())&&"0".equals(mesSend.getValue()) |
| | | &&"开工".equals(machine.getState()) |
| | | &&taskingCount.size()<machine.getMaxTaskCount())){ |
| | | Tasking tasking; |
| | | if(machine.getMode()==1){ |
| | | //标准模式 |
| | | tasking=taskingService.startMachineTask(machine); |
| | | }else{ |
| | | //定制模式 |
| | | String PlcRequestID_=plcRequestID.getValue(); |
| | | //String PlcRequestID_=",,46403118"; |
| | | scan_id= PlcRequestID_.substring(PlcRequestID_.lastIndexOf(",")+1); |
| | | tasking=taskingService.startScanIdMachineTask(machine,scan_id);//不管顺序,直接找从磨边机扫码后到翻片台的数据 |
| | | try { |
| | | PlcParameterInfo plcRequest = plcParameterObject.getPlcParameter("plcRequest");//请求字 |
| | | PlcParameterInfo plcRequestID = plcParameterObject.getPlcParameter("plcRequestID");//请求ID |
| | | PlcParameterInfo plcRequestType = plcParameterObject.getPlcParameter("plcRequestType");//PLC请求 |
| | | |
| | | PlcParameterInfo mesSend = plcParameterObject.getPlcParameter("mesSend");//发送字 |
| | | PlcParameterInfo mesSendId = plcParameterObject.getPlcParameter("mesSendID");//发送ID |
| | | PlcParameterInfo length = plcParameterObject.getPlcParameter("length");//长 |
| | | PlcParameterInfo width = plcParameterObject.getPlcParameter("width");//宽 |
| | | PlcParameterInfo mesSendType = plcParameterObject.getPlcParameter("mesSendType");// 扫码1 不扫码2 |
| | | |
| | | String scan_id = ""; |
| | | if (machine.getIsLog() > 0) { |
| | | s7objectMachine.consoleLogInfo(); |
| | | } |
| | | if(tasking!=null){ |
| | | log.info("4、发送数据:{},{},{},{},{}" |
| | | ,tasking.getGlassId(),tasking.getProgramId() |
| | | ,tasking.getLength().intValue(),tasking.getWidth().intValue(),1); |
| | | s7objectMachine.plccontrol.writeWord(length.getAddress(), tasking.getLength().intValue()); |
| | | s7objectMachine.plccontrol.writeWord(width.getAddress(), tasking.getWidth().intValue()); |
| | | s7objectMachine.plccontrol.writeString(mesSendId.getAddress(), tasking.getTaskSequence().toString()); |
| | | s7objectMachine.plccontrol.writeWord(mesSend.getAddress(), 1); |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String sendRecord=df.format(new Date())+" "+ |
| | | tasking.getGlassId()+"-"+ |
| | | tasking.getLength()+"-"+ |
| | | tasking.getWidth(); |
| | | if (sendRecords.size()>7){ |
| | | sendRecords.remove(0); |
| | | } |
| | | Map sendContentMap=new HashMap(); |
| | | sendContentMap.put("sendContent",sendRecord); |
| | | sendRecords.add(sendContentMap); |
| | | nullMachine(machine); |
| | | if ("0".equals(plcRequestType.getValue()) && !"0".equals(mesSendType.getValue())) { |
| | | //发送字置0 |
| | | log.info("1.发送类型字置零,清除上次发送的类型数据{}->0", mesSendType.getValue()); |
| | | s7objectMachine.plccontrol.writeWord(mesSendType.getAddress(), 0); |
| | | |
| | | return; |
| | | }else if(!scan_id.isEmpty()){ |
| | | taskingService.scanMachineAdd(machine,scan_id); |
| | | } |
| | | }else if("0".equals(plcRequest.getValue())){ |
| | | nullMachine(machine); |
| | | if ("0".equals(plcRequest.getValue()) && !"0".equals(mesSend.getValue())) { |
| | | //发送字置0 |
| | | int finishCount = taskingService.finishMachineTask(machine); |
| | | nullMachine(machine); |
| | | log.info("2.发送字置零,清除上次发送的数据{},{},{},{},{}" |
| | | , finishCount |
| | | , length.getValue() |
| | | , width.getValue() |
| | | , mesSendId.getValue() |
| | | , mesSend.getValue()); |
| | | s7objectMachine.plccontrol.writeWord(length.getAddress(), 0); |
| | | s7objectMachine.plccontrol.writeWord(width.getAddress(), 0); |
| | | s7objectMachine.plccontrol.writeWord(mesSendId.getAddress(), 0); |
| | | s7objectMachine.plccontrol.writeWord(mesSend.getAddress(), 0); |
| | | return; |
| | | } |
| | | if ("1".equals(plcRequestType.getValue()) && "0".equals(mesSendType.getValue())) { |
| | | //发送类型 1扫码 2不扫码 |
| | | int type = machine.getMode() == 1 ? 2 : 1; |
| | | log.info("3.发送类型数据0->{}", mesSendType.getValue()); |
| | | s7objectMachine.plccontrol.writeWord(mesSendType.getAddress(), type); |
| | | return; |
| | | } |
| | | List<Tasking> taskingCount = taskingService.findMachineWorkStateTask(machine, "正在工作"); |
| | | if (("1".equals(plcRequest.getValue()) && "0".equals(mesSend.getValue()) |
| | | && "开工".equals(machine.getState()) |
| | | && taskingCount.size() < machine.getMaxTaskCount())) { |
| | | Tasking tasking; |
| | | if (machine.getMode() == 1) { |
| | | //标准模式 |
| | | tasking = taskingService.startMachineTask(machine); |
| | | } else { |
| | | //定制模式 |
| | | String PlcRequestID_ = plcRequestID.getValue(); |
| | | //String PlcRequestID_=",,46403118"; |
| | | scan_id = PlcRequestID_.substring(PlcRequestID_.lastIndexOf(",") + 1); |
| | | tasking = taskingService.startScanIdMachineTask(machine, scan_id);//不管顺序,直接找从磨边机扫码后到翻片台的数据 |
| | | } |
| | | if (tasking != null) { |
| | | log.info("4、发送数据:{},{},{},{},{}" |
| | | , tasking.getGlassId(), tasking.getProgramId() |
| | | , tasking.getLength().intValue(), tasking.getWidth().intValue(), 1); |
| | | s7objectMachine.plccontrol.writeWord(length.getAddress(), tasking.getLength().intValue()); |
| | | s7objectMachine.plccontrol.writeWord(width.getAddress(), tasking.getWidth().intValue()); |
| | | s7objectMachine.plccontrol.writeString(mesSendId.getAddress(), tasking.getTaskSequence().toString()); |
| | | s7objectMachine.plccontrol.writeWord(mesSend.getAddress(), 1); |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String sendRecord = df.format(new Date()) + " " + |
| | | tasking.getGlassId() + "-" + |
| | | tasking.getLength() + "-" + |
| | | tasking.getWidth(); |
| | | if (sendRecords.size() > 7) { |
| | | sendRecords.remove(0); |
| | | } |
| | | Map sendContentMap = new HashMap(); |
| | | sendContentMap.put("sendContent", sendRecord); |
| | | sendRecords.add(sendContentMap); |
| | | nullMachine(machine); |
| | | return; |
| | | } else if (!scan_id.isEmpty()) { |
| | | taskingService.scanMachineAdd(machine, scan_id); |
| | | } |
| | | } else if ("0".equals(plcRequest.getValue())) { |
| | | nullMachine(machine); |
| | | } |
| | | } catch (Exception e) { |
| | | s7objectMachine.plccontrol.closeS7client(); |
| | | log.info("逻辑处理异常:设备id【{}】", machine.getId()); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | public void nullMachine(Machine machine) { |
| | | if (!"".equals(machine.getRemark())){ |
| | | if (!"".equals(machine.getRemark())) { |
| | | machine.setRemark(""); |
| | | machineMapper.updateById(machine); |
| | | } |
| | | } |
| | | |
| | | @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()); |
| | | } |
| | | } |
| | | } |