严智鑫
2024-04-24 e5e576ab6840b8030a60a1e67fb94728f7ec2ae2
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PLCAutoMes.java
New file
@@ -0,0 +1,48 @@
package com.mes.common;
import java.io.IOException;
import static com.mes.common.InitUtil.readAndUpdateWordValues;
public class PLCAutoMes extends Thread {
    private static InitUtil initUtil;
    // 单例实例
    private static PLCAutoMes instance;
    private static String PlcAlbania = PLCAutoMes.class.getResource("/JsonFile/PlcAlbania.json").getPath();
    public static PlcParameterObject PlcMesObject = InitUtil.initword(PlcAlbania);
    // 私有构造函数
    public PLCAutoMes() throws IOException {
        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);
        }
    }
}