ZengTao
2023-09-14 a7ab44bca33c0bfc85b301f6edc7398aecb74a81
springboot-vue3/src/main/java/com/example/springboot/component/S7control.java
@@ -10,15 +10,17 @@
public class S7control {
    S7PLC s7PLC; // PLC通讯类实例
    private EPlcType plcType = EPlcType.S1200; // 西门子PLC类型
    private String ip = "127.0.0.1"; // plc ip地址
    private int port = 21; // plc 端口号
    private EPlcType plcType = EPlcType.S1500; // 西门子PLC类型
    private String ip = "192.168.10.1"; // plc ip地址
    private int port = 102; // plc 端口号
    private static volatile S7control instance = null;
    private S7control() {
        if (s7PLC == null)
            s7PLC = new S7PLC(plcType, ip, port);
           s7PLC.connect();
            System.out.println(ip);
    }
    // 单例模式 获取类的唯一实例
@@ -145,6 +147,7 @@
    public List<Short> ReadWord(List<String> address) {
        if (!s7PLC.checkConnected())
            return null;
        return s7PLC.readInt16(address);
    }