ZengTao
2024-04-23 9057d8571f11a552a326fa35fda9b5ec614f5c58
springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java
@@ -1,9 +1,11 @@
package com.example.springboot.component;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.springboot.service.JdbcConnections;
import com.example.springboot.service.SpianService;
import com.example.springboot.service.SpianServiceNew;
import com.example.springboot.entity.north_glass_buffer1;
import com.example.springboot.mapper.AlarmMapper;
import com.example.springboot.mapper.SpianMapper;
@@ -16,6 +18,7 @@
  private JdbcConnections jdbcConnections;
  private SpianMapper spianMapper;
  private SpianService spianService;
  private SpianServiceNew spianServiceNew;
  int aaa;
  @Override
@@ -24,14 +27,16 @@
    while (this != null) {
      try {
        Thread.sleep(50);
        Thread.sleep(100);
      } 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);
      spianServiceNew = WebSocketServer.applicationContext.getBean(SpianServiceNew.class);
      jdbcConnections = WebSocketServer.applicationContext.getBean(JdbcConnections.class);
      // 根据玻璃id获取订单号,单独数据源
      // try {
@@ -41,27 +46,40 @@
      // // TODO Auto-generated catch block
      // e.printStackTrace();
      // }
      // 出片任务////////////////////////////////
      spianServiceNew.selectout2("X21942613103GV");
      List<Short> outlist = S7control.getinstance().ReadWord("DB106.20", 1); // 出片车状态
      List<Short> outlist1 = S7control.getinstance().ReadWord("DB105.18", 1); // 出片任务是否启动
      boolean Plcout = spianService.listbool("DB106.64"); // 出片请求字
      boolean Plcout2 = spianService.listbool("DB105.18"); // 出片启动
      if (Plcout == false&&Plcout2==true) {
        S7control.getinstance().WriteWord("DB105.18", (short) 0);// 出片任务启动改为0
        System.out.println("关闭出片启动" + LocalDateTime.now());// 出片任务发送字改为0
      }
      boolean Plcadd = spianService.listbool("DB106.24"); // 进片请求字
      boolean Plcadd2 = spianService.listbool("DB105.16"); // 进片启动
      if (Plcadd == false&&Plcadd2==true) {
        S7control.getinstance().WriteWord("DB105.16", (short) 0);//进片任务启动改为0
        System.out.println("关闭进片启动" + LocalDateTime.now());// 进片任务发送字改为0
      }
      // StringBuilder writedstrIdOut = new StringBuilder();
      // 获取已下发的出片id
      byte[] writedglassidbytesOut = S7control.getinstance().ReadByte("DB105.30", 14);
      String writedstrIdOut = new String(writedglassidbytesOut);
      boolean outstate = false;// 出片车空闲判断
      boolean outstate1 = false;// 出片车任务是否启动
      if (outlist != null && outlist1 != null) {
        outstate = outlist.contains((short) 0);// 出片车空闲判断 当出片车空闲时为true
        outstate1 = outlist1.contains((short) 1);// 出片车任务是否启动 当出片车任务启动时为true
      if (Plcout == true) {
        // 判断当前是否有未执行的任务
        int outnum = spianMapper.SelectOutSliceshu();
        int cageoutsum = spianMapper.Selectcageout(3);
        int outnum = spianMapper.SelectOutSliceshu();//是否有正在出片的任务
        int cageoutsum = spianMapper.Selectcageout(3);//笼子内是否还有在出片的玻璃
        // 当没有任务执行并且出片车空闲时
        if (outnum == 0 && outstate == true && Plchome.isAllowQueue == true && cageoutsum == 0) {
        if (outnum == 0 &&  Plchome.isAllowQueue == true && cageoutsum == 0) {
          // 判断铝框出片队列表是否有待出片的玻璃
          String outglassid = spianMapper.SelectOutSlice();
          // 当有待出片的玻璃时
@@ -72,18 +90,13 @@
            if (glassdisabled == 0) {
              spianService.selectout2(outglassid);
              Plchome.isQueueWarning = false;
              outstate = false;
            } else { // 禁用更改状态弹出提示
              Plchome.isQueueWarning = true;
            }
          }
        }
        if (outstate == true) {// 当出片车空闲时,且出片启动为1时,任务启动改为0
          if (outstate1 == true) {
            S7control.getinstance().WriteWord("DB105.18", (short) 0);// 出片任务启动改为0
          }
        }
      }
      ///////////// 进片任务
@@ -93,28 +106,46 @@
      boolean B01backs = spianService.listbool("DB106.60");// b01汇报
      boolean B02backs = spianService.listbool("DB106.62");// b02汇报
      StringBuilder B01glassid = spianService.queGlassid("DB103.184", 14);// BO1的玻璃id
      StringBuilder B02glassid = spianService.queGlassid("DB103.212", 14);// B02的玻璃id
      // 当进片小车完成任务时
      if (B01backs == true) {
        // 当B01小车汇报完成时更改玻璃状态 为1
        // spianService.overtask(B01glassid.toString());// 完成任务
        // S7control.getinstance().WriteWord("DB106.60", (short) 0);// 恢复B01小车应答改为0
        boolean yingda = spianService.listbool("DB106.60");// b01汇报
        System.out.println("汇报时B01|第" + aaa + "次" + B01glassid + "应答" + yingda);
        aaa += 1;
        // 判断是否汇报正确的id
        int HB = spianMapper.SelectHB(B01glassid.toString());
        if (HB > 0) {
          // 当B01小车汇报完成时更改玻璃状态 为1
          S7control.getinstance().WriteWord("DB105.48", (short) 1);// 恢复B01小车应答改为1
          boolean yingda = spianService.listbool("DB105.48");// b01汇报
          if (yingda == true) {
            spianService.overtask(B01glassid.toString());// 完成任务
          }
          System.out.println("汇报时B01|第" + aaa + "次" + B01glassid + "应答" + yingda);
          aaa += 1;
        }
      }else{
        S7control.getinstance().WriteWord("DB105.48", (short) 0);// 恢复B01小车应答改为1
      }
      // 当出片小车完成任务时
      if (B02backs == true) {
        // 当B02小车汇报完成时更改玻璃状态为0
        // spianService.overtask(B02glassid.toString());// 完成任务
        // S7control.getinstance().WriteWord("DB106.62", (short) 0);// 恢复B02小车应答改为0
        // 判断是否汇报正确的id
        int HB = spianMapper.SelectHB(B02glassid.toString());
        System.out.println("汇报时B02|" + B02glassid);
        boolean yingda1 = spianService.listbool("DB106.62");// b02汇报
        System.out.println("汇报时B02|第" + aaa + "次" + B02glassid + "应答" + yingda1);
        if (HB > 0) {
          // 当B02小车汇报完成时更改玻璃状态为0
          S7control.getinstance().WriteWord("DB105.50", (short) 1);// 恢复B02小车应答改为1
          System.out.println("汇报时B02ID|" + B02glassid);
          boolean yingda = spianService.listbool("DB105.50");// b02汇报
          if (yingda == true) {
            spianService.overtask(B02glassid.toString());// 完成任务
          }
          System.out.println("汇报时B02|第" + aaa + "次" + B02glassid + "应答" + yingda);
        }
      }else{
         S7control.getinstance().WriteWord("DB105.50", (short) 0);// 恢复B02小车应答改为0
      }
@@ -140,6 +171,7 @@
        }
      }
      if (queueid2 != null) {
        // 写入D02的数据到上片队列表
        if (glass2 == null) {
@@ -153,15 +185,6 @@
        }
      }
      // if (outstate == true) { // 出片车状态空闲时
      // Integer state = spianMapper.Selectoutstate();
      // String orderid = spianMapper.SelectOrderout();
      // if (orderid != null && state == 0) {
      // spianService.selectout(orderid);
      // }
      // }
      // 查询数据库
      // 推送到前端