ZengTao
2024-04-01 eccfd8d0504c48f07c7e11ed1fc94451ce5e7cb1
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
package com.example.springboot.component;
 
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
public class PlcInteractionState extends Thread {
    private Configuration config;
 
    public PlcInteractionState() throws IOException {
        config = new Configuration("config.properties");
    }
 
 
    // 创建一个自定义的 S7 控制器消息处理器对象
    MessageHandler customS7Control = new MessageHandler();
 
 
 
 
 
    @Override
    public void run() {
        while (this != null) {
            try {
                Thread.sleep(100);
 
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // this.readValue();
            // String PlcAddress = this.name;
            // Integer Plccount = this.count;
 
 
 
            List<String> addresses = Arrays.asList(config.getProperty("PlcInteractionState.MESImporttask").split(","));
 
            List<String> arraylist = S7control.getinstance().readStringsandword(addresses);
            // System.out.println(arraylist);
            List<String> addresses2 = Arrays.asList(config.getProperty("PlcInteractionState.PLCImporttask").split(","));
 
            List<String> arraylist2 = S7control.getinstance().readStringsandword(addresses2);
 
            List<String> addresses3 = Arrays.asList(config.getProperty("PlcInteractionState.MESProductiontask").split(","));
 
            List<String> arraylist3 = S7control.getinstance().readStringsandword(addresses3);
 
 
            List<String> addresses4 = Arrays.asList(config.getProperty("PlcInteractionState.PLCProductiontask").split(","));
 
            List<String> arraylist4 = S7control.getinstance().readStringsandword(addresses4);
 
 
            List<String> addresses5 = Arrays.asList(config.getProperty("PlcInteractionState.MEStaskinformation").split(","));
            List<String> arraylist5 = S7control.getinstance().readStringsandword(addresses5);
 
            List<String> addresses6 = Arrays.asList(config.getProperty("PlcInteractionState.MEStaskinformation2").split(","));
            List<String> arraylist6 = S7control.getinstance().readStringsandword(addresses6);
 
 
//            String[] values = { ".x11","x21 ","x21 ","x21 ","x21 ","x21"};
//   List<String> arraylist = new ArrayList<>(Arrays.asList(values));
//            String[] values2 = { ".x11 ","x21 ","x21 ","x21 ","x21 ","x21 ","x21 "};
//            List<String> arraylist2 = new ArrayList<>(Arrays.asList(values2));
//            String[] values3 = { ".x11 ","x21 ","x21 ","x21 ","x21 ","x21 "};
//            List<String> arraylist3 = new ArrayList<>(Arrays.asList(values3));
//            String[] values4 = { ".x11 ","x21 ","x21 ","x21 "};
//            List<String> arraylist4 = new ArrayList<>(Arrays.asList(values4));
//            String[] values5 = { ".x11 ","x21 ","x21 ","b02","x21 ","x21 "};
//            List<String> arraylist5 = new ArrayList<>(Arrays.asList(values5));
//
//            String[] values6 = { "x21 ","x21 ","x21 ","x21 ","x21 ","x21 ","x21 "};
//            List<String> arraylist6 = new ArrayList<>(Arrays.asList(values6));
 
 
 
            JSONObject jsonObject = new JSONObject();
            // System.out.println(arraylist6);
            JSONArray jsonArray = new JSONArray();
            jsonArray.put(arraylist);
            jsonArray.put(arraylist2);
            jsonArray.put(arraylist3);
            jsonArray.put(arraylist4);
            jsonArray.put(arraylist5);
            jsonArray.put(arraylist6);
            jsonObject.put("zuhe1", jsonArray);
 
 
//      WebSocketServer sendwServer = WebSocketServer.sessionMap.get("ManualonePosition");
//      if (sendwServer != null) {
//        sendwServer.sendMessage(jsonObject.toString());
//      }
 
            ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("InteractionState");
            if (sendwServer != null) {
                for (WebSocketServer webserver : sendwServer) {
                    webserver.sendMessage(jsonObject.toString());
 
 
                }
            }
        }
    }
}