wuyouming666
2024-05-14 1eadcf2fe21a211ba361b3cdb86a79f34b4b0479
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
package com.mes.common;
 
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import com.mes.tools.S7control;
 
 
 
 
public class S7object {
    public S7control plccontrol; // PLC通讯类实例
    private EPlcType plcType = EPlcType.S1500; // 西门子PLC类型
    private String ip = "192.168.10.1"; // plc ip地址
    private int port = 102; // plc 端口号
 
    private static volatile S7object instance = null;
 
    private S7object() {
        if (plccontrol == null) {
            plccontrol = new S7control(plcType, ip, port, 0, 0);
        }
    }
 
    // 单例模式 获取类的唯一实例
    public static S7object getinstance() {
        if (instance == null) {
            synchronized (S7object.class) {
                if (instance == null) {
                    instance = new S7object();
                }
            }
        }
        return instance;
    }
}