wuyouming666
2023-09-12 27a3b60fdd102fac12999684ead75a3a412ed66d
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
package com.example.springboot.component;
 
import cn.hutool.json.JSONObject;
 
import java.util.ArrayList;
import java.util.List;
 
public class Plcstate extends Thread {
  @Override
  public void run() {
    while (this != null) {
      try {
        Thread.sleep(10000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
 
      List<Short> plclist = S7control.getinstance().ReadWord("DB103.DBW0", 10);
      if (plclist == null) {
 
      } else {
 
        JSONObject jsonObject = new JSONObject();
        // jsonObject.append("sta",
        // new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, });
        jsonObject.append("sta", plclist);
        WebSocketServer sendwServer = WebSocketServer.sessionMap.get("State");
        if (sendwServer != null) {
          sendwServer.sendMessage(jsonObject.toString());
        }
 
      }
    }
  }
}