严智鑫
2024-05-07 0ec03c977e15aa7ac16c08e4fa4f0d4c901d19ee
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
package com.mes.common;
 
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.io.IOException;
 
import static com.mes.common.InitUtil.readAndUpdateWordValues;
 
public class PLCAutoMes extends Thread {
 
    private static final Logger log = LoggerFactory.getLogger(PLCAutoMes.class);
    private static InitUtil initUtil;
 
    // 单例实例
    private static PLCAutoMes instance;
    private static String PlcAlbania;
 
 
 
    public static PlcParameterObject PlcMesObject;
 
    // 私有构造函数
    public PLCAutoMes() throws IOException {
        PlcAlbania="D:\\SQL\\PlcCacheGlass.json";
//        PlcAlbania=PLCAutoMes.class.getResource("/JsonFile/PlcCacheGlass.json").getPath();
        //log.info(PLCAutoMes.class.getResource("").getPath());
        PlcMesObject = InitUtil.initword(PlcAlbania);
        initUtil = new InitUtil();
    }
 
    // 获取单例实例
    public static synchronized PLCAutoMes getInstance() throws IOException {
        if (instance == null) {
            instance = new PLCAutoMes();
        }
        return instance;
    }
 
    @Override
    public void run() {
        while (this != null) {
            try {
                Thread.sleep(100);
 
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
 
            readAndUpdateWordValues(PlcMesObject);
 
 
        }
    }
}