wu
2023-09-20 aaa2f09419a78299a01e80bd66ced6f6c5aa40bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package com.example.springboot.component;
 
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
 
import org.apache.ibatis.javassist.compiler.ast.Symbol;
import org.springframework.beans.factory.annotation.Autowired;
 
import com.example.springboot.service.JdbcConnections;
import com.example.springboot.service.SpianService;
import com.example.springboot.entity.Glass;
import com.example.springboot.mapper.AlarmMapper;
import com.example.springboot.mapper.SpianMapper;
 
public class PlcHold extends Thread {
 
  private AlarmMapper alarmMapper;
 
  @Autowired
  private JdbcConnections jdbcConnections;
  private SpianMapper spianMapper;
  private SpianService spianService;
 
  @Override
  public void run() {
    boolean inglassbegin=false;
    boolean outglassbegin=false;
    while (this != null) {
      try {
 
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        // \\ TODO Auto-generated catch block
        e.printStackTrace();
      }
      spianService = WebSocketServer.applicationContext.getBean(SpianService.class);
      spianMapper = WebSocketServer.applicationContext.getBean(SpianMapper.class);
      jdbcConnections = WebSocketServer.applicationContext.getBean(JdbcConnections.class);
 
      // 根据玻璃id获取订单号,单独数据源
      // try {
 
      //   Glass glass = jdbcConnections.selectGlass(112);
 
      //   // System.out.println(glass.getOrderId());
      // } catch (SQLException e) {
      //   // TODO Auto-generated catch block
      //   e.printStackTrace();
      // }
    // spianService.selectAll((short)257);
      //判断进片请求
      List<Short> datas1List = S7control.getinstance().ReadWord("DB106.24", 1);// 获取prc进片请求数据
      List<Short> datas1ListState = S7control.getinstance().ReadWord("DB106.8", 1);// 获取进片车状态
      List<Short> datas1ListState2 = S7control.getinstance().ReadWord("DB105.12", 1);// 获取进片车任务是否启动
        
      if (datas1List != null && datas1ListState != null) {
 
        // 获取prc进片请求数据
        boolean exist = datas1List.contains((short) 1);
        // 获取进片车状态
        boolean exist1 = datas1ListState.contains((short) 0);
        //判断进片车任务是否启动
        boolean exist2 = datas1ListState2.contains((short) 1);
       
        String glassid="";
        StringBuilder strId=new StringBuilder();
         StringBuilder writedstrId=new StringBuilder();
       
       if(!inglassbegin&!exist1)
       {
         inglassbegin=true;
       }
       if(inglassbegin&exist1)
       {
        inglassbegin=false;
        spianMapper.Updatetask(1, 0);//立即结束数据库表中的上片任务
        spianMapper.UpdataAddCageState(1,2);
       }
        // 进片请求为1时
        if (exist == true) {
          // 当进片车空闲时
          if (exist1 == true) {
            //获取已下发的进片id 与plc请求的id作比较
              byte[] writedglassidbytes = S7control.getinstance().ReadByte("DB105.16", 1);
            if (writedglassidbytes != null) {
              // 获取玻璃id
              for (byte iditem : writedglassidbytes) { 
                writedstrId.append(iditem);
              }
            }
            // 获取进片id
            byte[] datas1ListID = S7control.getinstance().ReadByte("DB106.26", 1);
            if (datas1ListID != null) {
              // 获取玻璃id
              for (byte list1 : datas1ListID) { 
                strId.append(list1);
                
              }
              if(!writedstrId.toString().equals(strId.toString())) //已经下发的id与plc请求的id不一样时,认为不是重复的任务,才执行下发任务指令
              {
                 spianService.selectAll(strId.toString());
                  S7control.getinstance().WriteByte("DB105.16",datas1ListID);//派发进片id
 
              }
              //spianService.selectAll(Short.parseShort(strId.toString()));
            }
 
          }
          // System.out.println(exist);
        }
//下发任务后将任务启动改为0
           if(exist1==false){  //进片车忙碌时
          if(exist2==true) {   //任务已启动时
          S7control.getinstance().WriteWord("DB105.12",(short)0);//进片任务启动改为0
          }  
        }
      }
      
      //spianService.selectAll((short) 111);
      
      List<Short> outlist = S7control.getinstance().ReadWord("DB106.20", 1); // 出片车状态
      List<Short> outlist1 = S7control.getinstance().ReadWord("DB105.14", 1); // 出片任务是否启动
      StringBuilder writedstrIdOut=new StringBuilder();
       //获取已下发的出片id
              byte[] writedglassidbytesOut = S7control.getinstance().ReadByte("DB105.30", 1);
            if (writedglassidbytesOut != null) {
              // 获取玻璃id
              for (byte iditem : writedglassidbytesOut) { 
                writedstrIdOut.append(iditem);
              }
            }
      boolean outstate=false;//出片车空闲判断
      boolean outstate1=false;//出片车任务是否启动
       if (outlist != null&&outlist1!=null) {
        // 判断按订单出片
         outstate = outlist.contains((short) 0);//出片车空闲判断
         outstate1 = outlist1.contains((short) 1);//出片车任务是否启动
         
          Glass glass=spianMapper.SelectDBOut();//判断是否有调拨后的出片任务未完成
 
          if(!outglassbegin&!outstate)//当任务还未开始,且出片车不空闲时,任务状态改为开始
       {
         outglassbegin=true;
       }
       if(outglassbegin&outstate)//当任务开始且出片车空闲时
       {
        outglassbegin=false;
        spianMapper.UpdatetaskOut(); //完成上一次出片或者调度任务
        spianMapper.UpdataAddCageState(0,3);
       }
 
         if(outstate== true &glass.getGlassId()!=null){ //当出片车空闲且有出片任务待完成时
          if(glass.getId()==2&!writedstrIdOut.toString().equals(glass.getGlassId().toString())){ 
           spianService.selectout2(glass.getGlassId().toString());
            }
        } 
        if(outstate==false){//下发任务后将任务启动改为0//出片车空闲判断
          if(outstate1==true){
            S7control.getinstance().WriteWord("DB105.14",(short)0);//出片任务启动改为0
          }
         }
      }
     
      
 
     
        if (outstate == true) { // 出片车状态空闲时
            Integer state=spianMapper.Selectoutstate();
            String orderid = spianMapper.SelectOrderout();
           
            if (orderid != null &&state==0) {
              spianService.selectout(orderid);
            }      
        }
 
      
 
      // 查询数据库
      // 推送到前端
 
    }
  }
 
}