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
| package com.example.springboot.component;
|
| import java.util.List;
|
| import javax.websocket.Session;
|
| import cn.hutool.json.JSONArray;
| import cn.hutool.json.JSONObject;
|
| public class PlcHold extends Thread {
| @Override
| public void run() {
| while (this != null) {
| try {
|
| Thread.sleep(10000);
| } catch (InterruptedException e) {
| // TODO Auto-generated catch block
| e.printStackTrace();
| }
| List<Boolean> bitlist = S7control.getinstance().ReadBits("DB2.0.0", 100);
|
| List<Short> paramlist = S7control.getinstance().ReadWord("DB100.6", 1);
|
| // 查询数据库
| // 推送到前端
|
| // Parameter
| // JSONObject jsonObject = new JSONObject();
| // jsonObject.append("params", new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, });
| // WebSocketServer sendwServer = WebSocketServer.sessionMap.get("Parameter");
| // if (sendwServer != null) {
| // sendwServer.sendMessage(jsonObject.toString());
| // }
|
| // Action
| // JSONObject jsonObject2 = new JSONObject();
| // jsonObject2.append("acion",
| // new short[] { 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
| // 1, 1, 1, 0, 0, });
| // WebSocketServer sendwServer2 = WebSocketServer.sessionMap.get("Action");
| // if (sendwServer2 != null) {
| // sendwServer2.sendMessage(jsonObject2.toString());
| // }
|
| // Sign
| JSONObject jsonObject3 = new JSONObject();
| jsonObject3.append("sig",
| new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0,
| 1, });
| WebSocketServer sendwServer3 = WebSocketServer.sessionMap.get("Sign");
| if (sendwServer3 != null) {
| sendwServer3.sendMessage(jsonObject3.toString());
| }
|
| // State
| JSONObject jsonObject4 = new JSONObject();
| jsonObject4.append("sta", new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, });
| WebSocketServer sendwServer4 = WebSocketServer.sessionMap.get("State");
| if (sendwServer4 != null) {
| sendwServer4.sendMessage(jsonObject4.toString());
| }
|
| }
| }
| }
|
|