| | |
| | | package com.example.springboot.component; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Date; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import com.example.springboot.service.JdbcConnections; |
| | | import com.example.springboot.service.SpianService; |
| | | import com.example.springboot.entity.north_glass_buffer1; |
| | | import com.example.springboot.service.SpianServiceNew; |
| | | import com.example.springboot.service.StorageCageService; |
| | | import com.example.springboot.entity.GlassInfo; |
| | | import com.example.springboot.entity.device.PlcParameterObject; |
| | | import com.example.springboot.mapper.AlarmMapper; |
| | | import com.example.springboot.mapper.SpianMapper; |
| | | import com.example.springboot.mapper.AlbaniaMapper; |
| | | |
| | | public class PlcHoldNew extends Thread { |
| | | |
| | | private AlarmMapper alarmMapper; |
| | | |
| | | @Autowired |
| | | private JdbcConnections jdbcConnections; |
| | | private SpianMapper spianMapper; |
| | | private SpianService spianService; |
| | | private AlbaniaMapper albaniaMapper; |
| | | private SpianServiceNew spianService; |
| | | private StorageCageService storageCageService; |
| | | int aaa; |
| | | String huibao = ""; |
| | | |
| | | @Override |
| | | public void run() { |
| | |
| | | while (this != null) { |
| | | try { |
| | | |
| | | Thread.sleep(100); |
| | | Thread.sleep(300); |
| | | } catch (InterruptedException e) { |
| | | // \\ TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | // if (S7control.getinstance().CheckConnected() == false) { |
| | | spianService = WebSocketServer.applicationContext.getBean(SpianService.class); |
| | | spianMapper = WebSocketServer.applicationContext.getBean(SpianMapper.class); |
| | | storageCageService = WebSocketServer.applicationContext.getBean(StorageCageService.class); |
| | | spianService = WebSocketServer.applicationContext.getBean(SpianServiceNew.class); |
| | | albaniaMapper = WebSocketServer.applicationContext.getBean(AlbaniaMapper.class); |
| | | spianService.selectout(1); |
| | | // 读取DB14区文件 |
| | | PlcParameterObject plcmes = PLCAutoMes.PlcMesObject; |
| | | if (plcmes.getPlcParameter("PLCToMES").getValue() != null) { |
| | | |
| | | //读取DB105区文件 |
| | | PlcParameterObject plcmes=PLCAutoMes.PlcMesObject; |
| | | //读106 |
| | | PlcParameterObject plcread=PLCAutoMes.PlcReadObject; |
| | | //读103 |
| | | PlcParameterObject plcstate=PLCAutoMes.plcStateObject; |
| | | String OutRequest=plcread.getPlcParameter("OutRequest").getValue();//出片请求 |
| | | String OutActivate=plcmes.getPlcParameter("OutActivate").getValue();//出片启动 |
| | | |
| | | |
| | | |
| | | //S7control.getinstance().WriteWord( plcmes.getPlcParameter("1231").getAddress(plcmes.getPlcParameter("1231").getAddressIndex()), (short) 0); |
| | | // 出片任务 |
| | | |
| | | if (OutActivate.equals("1") == false&&OutRequest.equals("1")==true) { |
| | | S7control.getinstance().WriteWord("DB105.18", (short) 0);// 出片任务启动改为0 |
| | | } |
| | | String FeedRequest=plcread.getPlcParameter("FeedRequest").getValue();// 进片请求字 |
| | | String AddActivate=plcmes.getPlcParameter("AddActivate").getValue();// 进片启动 |
| | | if (FeedRequest.equals("1") == false&&AddActivate.equals("1")==true) { |
| | | S7control.getinstance().WriteWord("DB105.16", (short) 0);//进片任务启动改为0 |
| | | } |
| | | |
| | | if (OutActivate.equals("1") == true) { |
| | | // 判断当前是否有未执行的任务 |
| | | int outnum = spianMapper.SelectOutSliceshu();//是否有正在出片的任务 |
| | | int cageoutsum = spianMapper.Selectcageout(3);//笼子内是否还有在出片的玻璃 |
| | | // 当没有任务执行并且出片车空闲时 |
| | | if (outnum == 0 && Plchome.isAllowQueue == true && cageoutsum == 0) { |
| | | // 判断铝框出片队列表是否有待出片的玻璃 |
| | | String outglassid = spianMapper.SelectOutSlice(); |
| | | // 当有待出片的玻璃时 |
| | | if (outglassid != null) { |
| | | // 获取该玻璃是否被禁用 |
| | | int glassdisabled = spianMapper.SelectCageGlassState(outglassid); |
| | | // 未禁用下发任务 |
| | | if (glassdisabled == 0) { |
| | | spianService.selectout2(outglassid); |
| | | Plchome.isQueueWarning = false; |
| | | } else { // 禁用更改状态弹出提示 |
| | | Plchome.isQueueWarning = true; |
| | | String ExportTOMES1 = plcmes.getPlcParameter("ExportTOMES1").getValue();// 出片请求一线 |
| | | String PLCToMES = plcmes.getPlcParameter("PLCToMES").getValue();// 运送车请求 |
| | | String IDStatus1 = plcmes.getPlcParameter("IDStatus1").getValue();// 1号任务完成 |
| | | String MESToPLCStatus1 = plcmes.getPlcParameter("MESToPLCStatus1").getValue();// 1号确认字 |
| | | String MESToPLC = plcmes.getPlcParameter("MESToPLC").getValue();// 发送任务字 |
| | | int taskcont = albaniaMapper.SelectTaskcount(); // 正在进行的任务数量 |
| | | int outtask = albaniaMapper.SelectOutTaskCount(); // 等待补发的出片任务数量 |
| | | if(outtask>0){ |
| | | spianService.mateOut(); |
| | | } |
| | | // String scan=plcmes.getPlcParameter("scan").getValue();//发送扫码信息 |
| | | // if(scan.equals("1")==true){ |
| | | // spianService.scan(scan); |
| | | // } |
| | | // 获取当前时间 |
| | | String currentTime = new Date().toString(); |
| | | if (!huibao.equals(IDStatus1)) { |
| | | System.out.println("汇报记录:" + IDStatus1 + "时间" + currentTime); |
| | | } |
| | | huibao = IDStatus1; |
| | | // 一号线请求 |
| | | if (ExportTOMES1 != null && MESToPLC != null && taskcont == 0) { |
| | | if (ExportTOMES1.equals("1") == true && MESToPLC.equals("0") == true && PLCToMES.equals("1") == true |
| | | && MESToPLCStatus1.equals("0") == true) { |
| | | System.out |
| | | .println("出片状态:MESToPLC:" + MESToPLC + "PLCToMES:" + PLCToMES + "MESToPLCStatus1:" + MESToPLCStatus1); |
| | | spianService.selectout(1); |
| | | try { |
| | | Thread.sleep(200); // 每100毫秒检查一次 |
| | | } catch (InterruptedException e) { |
| | | Thread.currentThread().interrupt(); // 处理线程中断 |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | ///////////// 进片任务 |
| | | |
| | | String B01backs = plcread.getPlcParameter("B01CompleteTheReport").getValue();// b01汇报 |
| | | String B02backs = plcread.getPlcParameter("B02CompleteTheReport").getValue();// b02汇报 |
| | | |
| | | String B01glassid = plcstate.getPlcParameter("B01ID1").getValue();// BO1的玻璃id |
| | | String B02glassid = plcstate.getPlcParameter("B02ID1").getValue();// B02的玻璃id |
| | | |
| | | // 当进片小车完成任务时 |
| | | if (B01backs.equals("1") == true) { |
| | | // 判断是否汇报正确的id |
| | | int HB = spianMapper.SelectHB(B01glassid.toString()); |
| | | if (HB > 0) { |
| | | // 恢复B01小车应答改为1 |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("B01report").getAddress(plcmes.getPlcParameter("B01report").getAddressIndex()), (short) 1); |
| | | String yingda =plcmes.getPlcParameter("B01report").getValue();// b01汇报 |
| | | if (yingda.equals("1")) { |
| | | spianService.overtask(B01glassid.toString());// 完成任务 |
| | | } |
| | | PLCToMES = plcmes.getPlcParameter("PLCToMES").getValue();// 运送车请求 |
| | | IDStatus1 = plcmes.getPlcParameter("IDStatus1").getValue();// 1号任务完成 |
| | | MESToPLCStatus1 = plcmes.getPlcParameter("MESToPLCStatus1").getValue();// 1号确认字 |
| | | MESToPLC = plcmes.getPlcParameter("MESToPLC").getValue();// 发送任务字 |
| | | // 运送车请求和测量完成请求 |
| | | GlassInfo glass = albaniaMapper.SelectGlass(); |
| | | if (PLCToMES != null && glass != null && MESToPLC != null && taskcont == 0) { |
| | | if (PLCToMES.equals("1") == true && MESToPLC.equals("0") == true && MESToPLCStatus1.equals("0") == true) { |
| | | try { |
| | | Thread.sleep(100); // 每100毫秒检查一次 |
| | | } catch (InterruptedException e) { |
| | | Thread.currentThread().interrupt(); // 处理线程中断 |
| | | } |
| | | System.out |
| | | .println("进片状态:MESToPLC:" + MESToPLC + "PLCToMES:" + PLCToMES + "MESToPLCStatus1:" + MESToPLCStatus1); |
| | | spianService.selectAll(glass); |
| | | } |
| | | } |
| | | |
| | | }else{ |
| | | // 恢复B01小车应答改为0 |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("B01report").getAddress(plcmes.getPlcParameter("B01report").getAddressIndex()), (short) 0); |
| | | } |
| | | // 任务完成时 |
| | | if ((IDStatus1.equals("1") && MESToPLCStatus1.equals("0")) || |
| | | (IDStatus1.equals("4") && MESToPLCStatus1.equals("0"))) { |
| | | // 完成确认字 |
| | | for (int i = 1; i < 7; i++) { |
| | | String Tastover = plcmes.getPlcParameter("IDStatus" + i).getValue();// PLC理片任务状态汇报 |
| | | String Glassid = plcmes.getPlcParameter("MESID" + i).getValueString();// MES玻璃ID |
| | | GlassInfo id = albaniaMapper.SelectTaskId(Glassid); |
| | | if (Tastover.equals("1")) { |
| | | // 调用完成任务 Glassid |
| | | storageCageService.FinishTask(); |
| | | System.out.println("完成任务ID:" + id); |
| | | } else if (Tastover.equals("4")) { |
| | | storageCageService.FinishTask(); |
| | | System.out.println("完成失败任务ID:" + id); |
| | | } |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCStatus" + i).getAddress(), (short) 1);// 完成确认字 |
| | | } |
| | | System.out.println("完成确认字MESToPLCStatus"); |
| | | // 清除任务地址 |
| | | for (int i = 1; i < 7; i++) { |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCStart" + i).getAddress(), (short) 0);// 清除任务地址 |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCTarget" + i).getAddress(), (short) 0);// 清除任务地址 |
| | | } |
| | | System.out.println("清除任务地址"); |
| | | while (true) { |
| | | String currentValue = plcmes.getPlcParameter("MESToPLC").getValue(); |
| | | // 检查 MESToPLC 的值是否为 0 |
| | | if (currentValue.equals("0")) { |
| | | System.out.println("MESToPLC 已变为 0,停止循环写入"); |
| | | break; // 退出循环 |
| | | } |
| | | // 如果不为 0,继续写入 |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), |
| | | (short) 0);// 清除任务发送字 |
| | | System.out.println("继续写入 MESToPLC,当前值:" + currentValue); |
| | | // 加上延时,避免占用过多 CPU 资源 |
| | | try { |
| | | Thread.sleep(100); // 例如每秒检查一次 |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | // 当出片小车完成任务时 |
| | | if (B02backs.equals("1") == true) { |
| | | // 判断是否汇报正确的id |
| | | int HB = spianMapper.SelectHB(B02glassid); |
| | | if (HB > 0) { |
| | | // 恢复B02小车应答改为1 |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("B02report").getAddress(plcmes.getPlcParameter("B02report").getAddressIndex()), (short) 1); |
| | | String yingda =plcmes.getPlcParameter("B01report").getValue();// b02应答 |
| | | if (yingda.equals("1") == true) { |
| | | spianService.overtask(B02glassid);// 完成任务 |
| | | } |
| | | } |
| | | }else{ |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("B02report").getAddress(plcmes.getPlcParameter("B02report").getAddressIndex()), (short) 0); |
| | | } |
| | | |
| | | |
| | | // 获取DO1数据 |
| | | String Do1ID=plcread.getPlcParameter("FeedID").getValue();// 获取请求的id跟DO1同时清 |
| | | // 获取DO2数据 |
| | | String Do2ID=plcread.getPlcParameter("FeedID").getValue();// 获取请求的id跟DO1同时清 |
| | | |
| | | |
| | | int questate = spianMapper.Selectquecount(Do1ID.toString());// 判断扫码位是否有玻璃已确认 |
| | | // queueid1.toString().isEmpty() |
| | | north_glass_buffer1 glass1 = spianMapper.selectGlass(Do1ID);// D01的玻璃信息 |
| | | north_glass_buffer1 glass2 = spianMapper.selectGlass(Do2ID);// D02玻璃信息 |
| | | // 当扫码位玻璃id为空时 宽度为0 |
| | | if (Do1ID != null && questate == 0) { |
| | | // 写入D01的数据到上片队列表 |
| | | if (glass1 == null) { // 当没有值时传空 |
| | | spianMapper.Updatequeue(null, null, null, null, 0, null, null, null, null, 1); |
| | | } else { |
| | | spianMapper.Updatequeue(Do1ID.toString(), glass1.getordernumber(), glass1.getlistnumber(), |
| | | glass1.getboxnumber(), 0, glass1.getglasslengthmm().toString(), glass1.getglassheightmm().toString(), |
| | | glass1.getglasslength().toString(), glass1.getglassheight().toString(), 1); |
| | | } |
| | | |
| | | } |
| | | // 汇报取消时 |
| | | if ((IDStatus1.equals("0")) && MESToPLCStatus1.equals("1")) { |
| | | // 取消确认字 |
| | | for (int i = 1; i < 7; i++) { |
| | | String Tastover = plcmes.getPlcParameter("IDStatus" + i).getValue();// 依次获取任务汇报 |
| | | if (Tastover.equals("0")) { |
| | | S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCStatus" + i).getAddress(), (short) 0);// 清除确认字 |
| | | |
| | | if (Do2ID != null) { |
| | | // 写入D02的数据到上片队列表 |
| | | if (glass2 == null) { |
| | | spianMapper.Updatequeue(null, null, null, null, 0, null, null, null, null, 2); |
| | | } else { |
| | | spianMapper.Updatequeue(Do2ID.toString(), glass2.getordernumber(), glass2.getlistnumber(), |
| | | glass2.getboxnumber(), 0, glass2.getglasslengthmm().toString(), glass2.getglassheightmm().toString(), |
| | | glass2.getglasslength().toString(), glass2.getglassheight().toString(), 2); |
| | | spianMapper.overqueue2(Do2ID.toString(), 0, 1);// 更改扫码位任务表的状态为0 |
| | | S7control.getinstance().WriteWord("DB105.16", (short) 0);// 关闭任务启动 |
| | | } |
| | | } |
| | | System.out.println("清除确认字MESToPLCStatus"); |
| | | } |
| | | |
| | | } |
| | |
| | | // 查询数据库 |
| | | // 推送到前端 |
| | | |
| | | // } |
| | | } |
| | | } |
| | | |