严智鑫
2024-04-18 ad28331c1e3ed456b72765874b41b83b49dc279f
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
package com.mes.common;
 
 
import java.io.IOException;
 
import static com.mes.common.InitUtil.readAndUpdateWordValues;
 
public class PLCAutoMes extends Thread {
 
    // // 用于存储应用程序的配置信息
    // private Configuration config;
    private static InitUtil initUtil;
    // public static PlcParameterObject PlcMesObject;
    // public static PlcParameterObject PlcReadObject;
    // public static PlcParameterObject PlcframeObject;
 
    // // 创建一个自定义的 S7 控制器消息处理器对象
    // MessageHandler customS7Control = new MessageHandler();
 
    // 单例实例
    private static PLCAutoMes instance;
    // private static String PlcMes = PLCAutoMes.class.getResource("/JsonFile/PlcMes.json").getPath();
    private static String PlcAlbania = PLCAutoMes.class.getResource("/JsonFile/PlcAlbania.json").getPath();
    // private static String PlcRead = PLCAutoMes.class.getResource("/JsonFile/PlcRead.json").getPath();
    // private static String Plcframe = PLCAutoMes.class.getResource("/JsonFile/Plcframe.json").getPath();
    // private static String PlcParameter = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcParameter.json").getPath();
 
    // private static String PlcSign = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcSign.json").getPath();
 
    // private static String PlcState = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcState.json").getPath();
 
    // private static String PlcAlarm = PLCAutoMes.class.getResource("/JsonFile/PlcAlarm.json").getPath();
    // private static String PlcTest = PLCAutoMes.class.getResource("/JsonFile/PlcTest.json").getPath();
 
    // 调用initword方法
 
    // public static PlcParameterObject plcParameterObject = initUtil.initword(PlcParameter);
    // public static PlcBitObject plcPlcTest = initUtil.initbit(PlcTest);
    // public static PlcBitObject  plcBitObject = initUtil.initbit(PlcSign);
    // public static PlcParameterObject  plcStateObject= initUtil.initword(PlcState);
    // public static PlcBitObject plcPlcAlarm = initUtil.initbit(PlcAlarm);
    public static PlcParameterObject PlcMesObject = InitUtil.initword(PlcAlbania);
    // public static PlcParameterObject PlcReadObject = initUtil.initword(PlcRead);
    // public static PlcParameterObject PlcframeObject = initUtil.initword(Plcframe);
 
    // 私有构造函数
    public PLCAutoMes() throws IOException {
        //config = new Configuration("config.properties");
        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();
            }
 
            // System.out.println(jsonFilePath);
 
            //readAndUpdateWordValues(PlcReadObject);
            readAndUpdateWordValues(PlcMesObject);
            //readAndUpdateWordValues(PlcframeObject);
            // readAndUpdateWordValues(PlcframeObject);
 
            // readAndUpdateWordValues(plcStateObject);
            // int index = PlcMesObject.getPlcParameter("AddStart").getAddressIndex();
            // // System.out.println(index);
            // PlcMesObject.getPlcParameter("AddStart").getAddress(index);
            // // System.out.println(PlcMesObject.getPlcParameter("AddStart").getAddress(index));
            // List<String> addresses = new ArrayList<>();
            // addresses.add("FeedID");
            // addresses.add("AddStart");
            // // System.out.println(addresses);
            // // System.out.println(PlcMesObject.getPlcParameterValues(addresses));
            // List<String> addresses2 = new ArrayList<>();
            // addresses2.add("FeedID");
            // addresses2.add("FeedCarStatus");
 
            //System.out.println(PlcReadObject.getPlcParameterValues(addresses2));
 
        }
    }
}