| | |
| | | // \\ TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | // if (S7control.getinstance().CheckConnected() == false) { |
| | | spianService = WebSocketServer.applicationContext.getBean(SpianServiceNew.class); |
| | | albaniaMapper = WebSocketServer.applicationContext.getBean(AlbaniaMapper.class); |
| | | |
| | | spianService.selectAll(albaniaMapper.SelectGlass()); |
| | | //读取DB14区文件 |
| | | PlcParameterObject plcmes=PLCAutoMes.PlcMesObject; |
| | | |
| | | //读103 |
| | | |
| | | |
| | | String ExportTOMES1=plcmes.getPlcParameter("ExportTOMES1").getValue();//出片请求一线 |
| | | String ExportToMES2=plcmes.getPlcParameter("ExportToMES2").getValue();//出片请求二线 |
| | | String PLCToMES=plcmes.getPlcParameter("PLCToMES").getValue();//进片请求 |
| | | String B01State=plcmes.getPlcParameter("B01State").getValue();//运送车请求 |
| | | String TastState=plcmes.getPlcParameter("MESToPLCStatus1").getValue();//任务完成 |
| | | String TastType=plcmes.getPlcParameter("TastType").getValue();//任务类型 |
| | | |
| | | |
| | | //调用出片任务 |
| | | if (ExportTOMES1.equals("1") == false&&PLCToMES.equals("0")==true) { |
| | | //一号线请求 |
| | | if (ExportTOMES1.equals("1") == true&&B01State.equals("0")==true) { |
| | | //将运输车状态改为忙碌 |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("B01report").getAddress(plcmes.getPlcParameter("B01report").getAddressIndex()), (short) 1); |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("B01report").getAddress(), (short) 1); |
| | | spianService.selectout(1); |
| | | } |
| | | //二线请求时 |
| | | if (ExportToMES2.equals("1") == false&&PLCToMES.equals("0")==true) { |
| | | //二线号请求时 |
| | | if (ExportToMES2.equals("1") == true&&B01State.equals("0")==true) { |
| | | //将运输车状态改为忙碌 |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("B01report").getAddress(plcmes.getPlcParameter("B01report").getAddressIndex()), (short) 1); |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("B01report").getAddress(), (short) 1); |
| | | spianService.selectout(2); |
| | | } |
| | | //调用进片任务 |
| | | //进片请求时 |
| | | if(PLCToMES.equals("1")==true&&B01State.equals("0")==true){ |
| | | //将运输车状态改为忙碌 |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("B01report").getAddress(plcmes.getPlcParameter("B01report").getAddressIndex()), (short) 1); |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("B01report").getAddress(), (short) 1); |
| | | |
| | | spianService.selectAll(albaniaMapper.SelectGlass()); |
| | | } |
| | |
| | | |
| | | //任务完成时 |
| | | if(TastState.equals("1")==true){ |
| | | |
| | | //完成确认字 |
| | | for(int i=1;i<7;i++){ |
| | | String Tastover=plcmes.getPlcParameter("IDStatus"+i).getValue();//依次获取任务类型 |
| | | String Glassid=plcmes.getPlcParameter("MESID"+i).getValue();//依次获取任务类型 |
| | | if(Tastover.equals("1")){ |
| | | |
| | | //调用完成任务 Glassid |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCStatus"+i).getAddress(), (short) 1);//完成确认字 |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | package com.example.springboot.entity; |
| | | |
| | | |
| | | //出片任务表 |
| | | |
| | | public class StorageTask{ |
| | | private Integer id;//自序 |
| | | private String taskType;//类型 |
| | |
| | | private String shelfRack;//起始位 |
| | | private String loadrack;//目标位 |
| | | private Integer count;//玻璃数量 |
| | | |
| | | private Integer glasstype;//玻璃类型 |
| | | private Integer flowcard;//流程卡 |
| | | private Integer mateid;//配片id |
| | | private Integer tier;//片序 |
| | | |
| | | public Integer id() { |
| | | return id; |
| | |
| | | this.loadrack = loadrack; |
| | | } |
| | | |
| | | |
| | | public Integer getGlasstype() { |
| | | return glasstype; |
| | | } |
| | | |
| | | public void setGlasstype(Integer glasstype) { |
| | | this.glasstype = glasstype; |
| | | } |
| | | public Integer getFlowcard() { |
| | | return flowcard; |
| | | } |
| | | |
| | | public void setFlowcard(Integer flowcard) { |
| | | this.flowcard = flowcard; |
| | | } public Integer getMateid() { |
| | | return mateid; |
| | | } |
| | | |
| | | public void setMateid(Integer mateid) { |
| | | this.mateid = mateid; |
| | | } |
| | | public Integer geTier() { |
| | | return tier; |
| | | } |
| | | |
| | | public void setTier(Integer tier) { |
| | | this.tier = tier; |
| | | } |
| | | |
| | | } |
| | |
| | | import org.apache.ibatis.annotations.Update; |
| | | import org.springframework.stereotype.Repository; |
| | | import com.example.springboot.entity.GlassInfo; |
| | | import com.example.springboot.entity.StorageCage; |
| | | |
| | | @Mapper |
| | | @Repository |
| | | public interface AlbaniaMapper { |
| | | //判断笼内是否有合适的类型空格 |
| | | @Select("select id from storage_cage where glasstype=#{glasstype} and width>=#{width}+#{widths} order by id limit 1") |
| | | @Select("select id from storage_cage where glasstype=#{glasstype} and width>=#{width}+#{widths} and state=0 order by id limit 1") |
| | | int SelectCage(int glasstype,Double width,int widths); |
| | | //判断笼内没有玻璃的空格 |
| | | @Select("select id from storage_cage where number=0 and cage>#{cage} and cage<#{cage2} order by id limit 1") |
| | |
| | | @Update("update storage_cage set number=number-1,width=width+glasswidth where id=#{id}") |
| | | void UpdateCageNumberOut(int id); |
| | | //增加任务记录 |
| | | @Insert("INSERT INTO `canadames`.`storage_task`(`task_type`, `task_state`, `shelf_rack`, `load_rack`,start_time,glass_id,count,finsh_time) VALUES (#{tasktype},#{taskstate},#{shelfrack},#{loadrack},now(),#{glassid},#{count},#{qidong});") |
| | | void Inserttask(int tasktype, int taskstate, int shelfrack, int loadrack, String glassid, int count,int qidong); |
| | | @Insert("INSERT INTO `albania`.`storage_task`(`task_type`, `task_state`, `shelf_rack`, `load_rack`,start_time,glass_id,glasstype,flowcard,mateid,tier) VALUES (#{tasktype},#{taskstate},#{shelfrack},#{loadrack},now(),#{glassid},#{glasstype},#{flowcard},#{mateid},#{tier});") |
| | | void Inserttask(int tasktype, int taskstate, int shelfrack, int loadrack, String glassid, int glasstype,String flowcard,int mateid,int tier); |
| | | //新增一条笼子数据 |
| | | @Update("UPDATE `albania`.`storage_cage` SET `glass_id` =#{glassid}, `width` =width-#{glasswidth}, `glasswidth` =#{glasswidth}, `glassheight` =#{glassheight}, `glasswidthmm` =#{glasswidthmm}, `glassheightmm` = #{glassheightmm}, `state` = #{state}, `glasstype` = #{glasstype}, `number` = #{number} WHERE `id` =#{id};") |
| | | void AddCage(int id,String glassid,Double glasswidth,Double glassheight,Double glasswidthmm,Double glassheightmm,int state,int glasstype,int number); |
| | | //获取进片数据 |
| | | @Select("select glassid,flowcard,glasswidth as width,glassheight as height,glasswidthmm,glassheightmm,glasstype from queue where glasstype=1") |
| | | @Select("select glassid,flowcard,glasswidth as width,glassheight as height,glasswidthmm,glassheightmm,glasstype from queue where state=0 limit 1") |
| | | GlassInfo SelectGlass(); |
| | | //一号线查询任务 |
| | | @Select("select * from v_cagerelease1 where mateid not in(select mateid from v_cagerelease1 where surplus=0 group by mateid);") |
| | | GlassInfo SelectOutGlass1(); |
| | | //二号线查询任务 |
| | | @Select("select * from v_cagerelease2 where mateid not in(select mateid from v_cagerelease2 where surplus=0 group by mateid)LIMIT 1;") |
| | | GlassInfo SelectOutGlass2(); |
| | | //流程卡任务查询 |
| | | @Select("select G.flowcard,G.glasstype,G.number,G.mateid,G.tier,G.starttime,G.finishnumber,IF((G.number-G.finishnumber-ku.KuCount)<0,G.number,ku.KuCount) as 'surplus',G.totaltier as id from (select Gfd.flowcard,Ggf.glasstype,Ggf.number,Ggf.mateid,Ggf.tier,Ggf.finishnumber,Gfd.starttime,Gfd.totaltier from flowcard as Gfd LEFT JOIN glassinfo as Ggf on Gfd.flowcard=Ggf.flowcard where Gfd.state=1 and Gfd.line=#{line}) as G left join (select glasstype,sum(number) AS KuCount from storage_cage where flowcard is not null group by glasstype) as ku on G.glasstype=ku.glasstype where G.mateid not in(select mateid from v_cagerelease1 where surplus=0 group by mateid)order by `g`.`starttime`,`g`.`mateid`,`g`.`finishnumber`,`g`.`tier`LIMIT 1;") |
| | | GlassInfo SelectOutGlass(int line); |
| | | //获取该类型在库存的位置 |
| | | @Select("select * from storage_cage where glasstype=#{glasstype} and number>0 limit 1") |
| | | StorageCage SelectCageGlass(int glasstype); |
| | | //发送出片后增加已发数量 |
| | | @Update("update glassinfo set finishnumber=finishnumber+1 where flowcard=#{flowcard} and mateid=#{mateid} and tier=#{tier};") |
| | | void AddFinishNumber(String flowcard,int mateid,int tier); |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | import com.example.springboot.entity.GlassInfo; |
| | | import com.example.springboot.entity.MeasureSetting; |
| | | import com.example.springboot.mapper.GlassInfoMapper; |
| | | import com.example.springboot.mapper.MeasureSettingMapper; |
| | | import com.example.springboot.mapper.QueueMapper; |
| | | // import com.example.springboot.mapper.GlassInfoMapper; |
| | | // import com.example.springboot.mapper.MeasureSettingMapper; |
| | | // import com.example.springboot.mapper.QueueMapper; |
| | | |
| | | @Service |
| | | public class HomeService { |
| | | |
| | | @Autowired |
| | | MeasureSettingMapper MeasureSettingMapper; |
| | | @Autowired |
| | | GlassInfoMapper GlassInfoMapper; |
| | | @Autowired |
| | | QueueMapper QueueMapper; |
| | | // @Autowired |
| | | // MeasureSettingMapper MeasureSettingMapper; |
| | | // @Autowired |
| | | // GlassInfoMapper GlassInfoMapper; |
| | | // @Autowired |
| | | // QueueMapper QueueMapper; |
| | | |
| | | // 匹配玻璃 宽,高,线路 |
| | | public List<GlassInfo> NormalGlassInfo(double width, double height, String line) { |
| | | // |
| | | List<GlassInfo> Results=new ArrayList<GlassInfo>(); |
| | | // 获取匹配设置 |
| | | MeasureSetting MeasureSetting = MeasureSettingMapper.SelectMeasureSetting(line); |
| | | if (height > 0 && width > 0 && MeasureSetting != null) { |
| | | // 有效参数 请求=1 长/宽>0 |
| | | double maxheight = height + MeasureSetting.getErrorHeight(); |
| | | double minheight = height - MeasureSetting.getErrorHeight(); |
| | | double maxwidth = width + MeasureSetting.getErrorWidth(); |
| | | double minwidth = width - MeasureSetting.getErrorWidth(); |
| | | // 查询当前测量数据 |
| | | List<GlassInfo> GlassInfos = GlassInfoMapper.selectGlassInfos(maxwidth, minwidth, maxheight, minheight); |
| | | List types = new ArrayList<>(); |
| | | for (int i = 0; i < GlassInfos.size(); i++) { |
| | | Integer glasstype = GlassInfos.get(i).getGlasstype(); |
| | | if (!types.contains(glasstype)) { |
| | | types.add(glasstype); |
| | | Results.add(GlassInfos.get(i)); |
| | | } |
| | | } |
| | | } |
| | | return Results; |
| | | } |
| | | // // 匹配玻璃 宽,高,线路 |
| | | // public List<GlassInfo> NormalGlassInfo(double width, double height, String line) { |
| | | // // |
| | | // List<GlassInfo> Results=new ArrayList<GlassInfo>(); |
| | | // // 获取匹配设置 |
| | | // MeasureSetting MeasureSetting = MeasureSettingMapper.SelectMeasureSetting(line); |
| | | // if (height > 0 && width > 0 && MeasureSetting != null) { |
| | | // // 有效参数 请求=1 长/宽>0 |
| | | // double maxheight = height + MeasureSetting.getErrorHeight(); |
| | | // double minheight = height - MeasureSetting.getErrorHeight(); |
| | | // double maxwidth = width + MeasureSetting.getErrorWidth(); |
| | | // double minwidth = width - MeasureSetting.getErrorWidth(); |
| | | // // 查询当前测量数据 |
| | | // List<GlassInfo> GlassInfos = GlassInfoMapper.selectGlassInfos(maxwidth, minwidth, maxheight, minheight); |
| | | // List types = new ArrayList<>(); |
| | | // for (int i = 0; i < GlassInfos.size(); i++) { |
| | | // Integer glasstype = GlassInfos.get(i).getGlasstype(); |
| | | // if (!types.contains(glasstype)) { |
| | | // types.add(glasstype); |
| | | // Results.add(GlassInfos.get(i)); |
| | | // } |
| | | // } |
| | | // } |
| | | // return Results; |
| | | // } |
| | | } |
| | |
| | | ids = cages1.getId();// 数据库ID |
| | | tiers = cages1.getTier();// 内外片 |
| | | cells = cages1.getCell();// 格子号 |
| | | prcid = cages1.getPrcId();// 传给prc的目标地id |
| | | //prcid = cages1.getPrcId();// 传给prc的目标地id |
| | | width = cages1.getWidth();// 格子剩余宽度 |
| | | widths = glasslist.getglasslengthmm(); |
| | | |
| | | // 执行进片 |
| | | datas.add((short) 1000);// 起始位置 |
| | | datas.add((short) prcid);// 目标位置 |
| | | datas.add((short) 1);// 目标位置 |
| | | datas.add((short) widths);// 进片玻璃宽 |
| | | datas.add((short) prctier); // 玻璃数 |
| | | datas.add((short) 1);// 任务启动 |
| | |
| | | int cage = cageout.getCage(); // 储存出片位置,笼子格子几号玻璃 |
| | | int cell = cageout.getCell();// 出片格号 |
| | | int tier = cageout.getTier();// 出片内外片 |
| | | int prcid = cageout.getPrcId();// prcid |
| | | //int prcid = cageout.getPrcId();// prcid |
| | | int prcid2; |
| | | int ids; |
| | | int cages; |
| | |
| | | int state = spianMapper.selectGlassState(cage, cell);// 获取格子数量 |
| | | // 判断玻璃可直接出片时 |
| | | // 修改数据库笼子表(出片) |
| | | datas.add((short) prcid); |
| | | datas.add((short) 1); |
| | | datas.add((short) 1000); |
| | | datas.add((short) state); |
| | | datas.add((short) 1); |
| | |
| | | // 判断内片是否需要调拨 |
| | | if (state == 1) { |
| | | // spianMapper.UpdataGlassCage("", "", glasswidth, cage, cell, tier, 3); |
| | | datas.add((short) prcid); |
| | | datas.add((short) 1); |
| | | datas.add((short) 1000); |
| | | datas.add((short) 1); |
| | | datas.add((short) 1); |
| | |
| | | return (300); |
| | | } |
| | | // 获取调拨位置进行调拨 |
| | | prcid2 = cagecell.getPrcId();// 调拨目标位PRCID |
| | | //prcid2 = cagecell.getPrcId();// 调拨目标位PRCID |
| | | ids = cagecell.getId();// 调拨目标位ID |
| | | cages = cagecell.getCage();// 调拨目标位笼子 |
| | | cells = cagecell.getCell();// 调拨目标位格子 |
| | | |
| | | // 填入调拨数据 |
| | | datas.add((short) prcid);// 调拨外片起始位置 |
| | | datas.add((short) prcid2); |
| | | datas.add((short) 1);// 调拨外片起始位置 |
| | | datas.add((short) 1); |
| | | datas.add((short) 2); |
| | | datas.add((short) 1); |
| | | // 更换玻璃的笼子 |
| | |
| | | return (300); |
| | | } |
| | | // 获取调拨位置进行调拨 |
| | | prcid2 = cagecell.getPrcId();// 调拨目标位prcID |
| | | //prcid2 = cagecell.getPrcId();// 调拨目标位prcID |
| | | ids = cagecell.getId();// 调拨目标位ID |
| | | cages = cagecell.getCage();// 调拨目标位笼子 |
| | | cells = cagecell.getCell();// 调拨目标位格子 |
| | | // 填入调拨数据 |
| | | datas.add((short) prcid); |
| | | datas.add((short) prcid2); |
| | | datas.add((short) 1); |
| | | datas.add((short) 1); |
| | | datas.add((short) 2); |
| | | datas.add((short) 1); |
| | | String glassids = spianMapper.SelectGlassid(cage, cell); // 获取被调拨的玻璃id |
| | |
| | | import com.example.springboot.component.PLCAutoMes; |
| | | import com.example.springboot.component.S7control; |
| | | import com.example.springboot.entity.GlassInfo; |
| | | import com.example.springboot.entity.StorageCage; |
| | | import com.example.springboot.entity.GlassInfo; |
| | | import com.example.springboot.entity.device.PlcParameterObject; |
| | | import com.example.springboot.mapper.AlbaniaMapper; |
| | | import com.google.common.primitives.Bytes; |
| | |
| | | int cageid; |
| | | String glassid=glassInfo.getGlassid(); |
| | | Double width=glassInfo.getWidth(); |
| | | Double height=glassInfo.getHeight(); |
| | | //int mateid=glassInfo.getMateid(); |
| | | String flowcard=glassInfo.getFlowcard(); |
| | | int glasstype=glassInfo.getGlasstype(); |
| | | |
| | | |
| | | |
| | | //判断是否有同类型的 |
| | | cageid=albaniaMapper.SelectCage(glassInfo.getGlasstype(), glassInfo.getWidth(), 50); |
| | | cageid=albaniaMapper.SelectCage(glasstype,width, 50); |
| | | //如果有同类型时直接增加 |
| | | if(cageid!=Integer.MIN_VALUE){ |
| | | //发送plc任务 |
| | | //Mestast(glassid,1001,cageid,1); |
| | | |
| | | //任务完成后增加数量 |
| | | albaniaMapper.UpdateCageNumberAdd(cageid); |
| | | }else{ |
| | | }else{ |
| | | //判断玻璃是否进入大片笼 |
| | | if(glassInfo.getThickness()>=15){ |
| | | cageid=albaniaMapper.SelectNewCell(3,5); |
| | |
| | | //发送plc任务 |
| | | } |
| | | //当返回的格子号为空时,返回400笼子已满 |
| | | if(cageid==Integer.MIN_VALUE){ |
| | | return(400); |
| | | if(cageid!=Integer.MIN_VALUE){ |
| | | Mestast(glassid,1001,cageid,1); |
| | | //发送plc任务 |
| | | |
| | | }else{ |
| | | //判断完成任务后增加数量 |
| | | albaniaMapper.AddCage(cageid, glassid, width, height, width, height, 0, glasstype, 1); |
| | | return(400); |
| | | } |
| | | } |
| | | //增加任务记录 |
| | | albaniaMapper.Inserttask(0, 0, 0, cageid, glassInfo.getGlassid(), 0, 0); |
| | | albaniaMapper.Inserttask(0, 0, 1001, cageid, glassid,glasstype, flowcard,0,0); |
| | | return(200); |
| | | |
| | | } |
| | | |
| | | |
| | | //出片 |
| | | public Short selectout(int line) { |
| | | //判断笼子最先出哪片 |
| | | |
| | | int mateid; |
| | | int glasstype; |
| | | int tier; |
| | | int sumid; |
| | | String flowcard; |
| | | GlassInfo glassmate=new GlassInfo(); |
| | | |
| | | for(int i=1;i<=7;i++){ |
| | | glassmate= albaniaMapper.SelectOutGlass(line); |
| | | mateid=glassmate.getMateid(); |
| | | glasstype=glassmate.getGlasstype(); |
| | | tier=glassmate.getTier(); |
| | | sumid=glassmate.getId(); |
| | | flowcard=glassmate.getFlowcard(); |
| | | |
| | | StorageCage glass= albaniaMapper.SelectCageGlass(glasstype); |
| | | //发送配片数据 |
| | | Mestast(glassmate.getGlasstype()+"i", glass.getId(),2002, 0); |
| | | albaniaMapper.AddFinishNumber(flowcard, mateid, tier); |
| | | albaniaMapper.Inserttask(1, 0, glass.getId(), 2002, glassmate.getGlassid()+i, glasstype,glass.getFlowcard(),mateid,tier); |
| | | if(tier==sumid){ |
| | | //本次配片完成发送启动命令 |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short)2);//出片任务启动 |
| | | return (200);//结束 |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | return(200);// 结束 |
| | | } |
| | |
| | | } |
| | | byte[] bytes = Bytes.toArray(glassidlist); |
| | | System.out.println("outmesidbytes:" + bytes.length); |
| | | S7control.getinstance().WriteByte(plcmes.getPlcParameter(address).getAddress(plcmes.getPlcParameter(address).getAddressIndex()),bytes); |
| | | S7control.getinstance().WriteByte(plcmes.getPlcParameter(address).getAddress(),bytes); |
| | | //S7control.getinstance().WriteByte(address, bytes);// 派发出片id |
| | | |
| | | } |
| | |
| | | writedstrIdOut.append((char) iditem); |
| | | } |
| | | } |
| | | return writedstrIdOut; |
| | | return writedstrIdOut; |
| | | } |
| | | |
| | | // char数组转化成bit数组 |
| | |
| | | return listbool; |
| | | } |
| | | |
| | | // 根据玻璃id完成在进行中的任务 |
| | | public void overtask(String glassid) { |
| | | |
| | | // spianMapper.UpdatetaskOut(glassid.toString());// 完成上一次 出片或者进片任务 |
| | | // spianMapper.OverOutSlice(glassid.toString(), 2, 1);// 完成出片队列任务 |
| | | // spianMapper.UpdataGlassCage(glassid.toString(), 0);// 清除出片格子玻璃信息 |
| | | // spianMapper.UpdateCageOver(glassid.toString(), 0);// 更改笼子表出片状态 |
| | | // spianMapper.UpdateCageadd(glassid.toString(), 1);// 更改笼子表进片状态 |
| | | // spianMapper.UpdateAddQueue(glassid.toString());// 把进片的玻璃更新到出片队列中 |
| | | //下发理片任务 |
| | | public void Mestast(String glassid,int MESToPLCStart1,int MESToPLCTarget1,int MESToPLC) { |
| | | outmesid(glassid, "MESID1");//下发玻璃id |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCStart1").getAddress(), (short) MESToPLCStart1);//起始位置 |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCTarget1").getAddress(), (short) MESToPLCTarget1);//目标位置 |
| | | if(MESToPLC!=0){ |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short)MESToPLC);//mes理片任务类型 |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |