严智鑫
2024-05-29 62c74409a587d9921df1a2248ce23b3b0375fbd1
hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/common/S7object.java
@@ -1,24 +1,31 @@
package com.mes.common;
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import com.mes.device.PlcParameterObject;
import com.mes.tools.InitUtil;
import com.mes.tools.S7control;
/**
 * @Author : zhoush
 * @Date: 2024/4/9 15:13
 * @Description:
 */
public class S7object {
public class S7object extends Thread {
    public S7control plccontrol; // PLC通讯类实例
    private EPlcType plcType = EPlcType.S1500; // 西门子PLC类型
    private String ip = "192.168.10.1"; // plc ip地址
    private EPlcType plcType = EPlcType.S200_SMART; // 西门子PLC类型
    private String ip = "192.168.10.100"; // plc ip地址
    private int port = 102; // plc 端口号
    public PlcParameterObject PlcMesObject;
    private static volatile S7object instance = null;
    private S7object() {
        if (plccontrol == null) {
            plccontrol = new S7control(plcType, ip, port, 0, 0);
            String PlcLoadGlass = System.getProperty("user.dir") + "/JsonFile/PlcLoadGlass.json";
            PlcMesObject = InitUtil.initword(PlcLoadGlass);
        }
    }
@@ -33,4 +40,21 @@
        }
        return instance;
    }
    @Override
    public void run() {
        while (this != null) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            byte[] getplcvlues = plccontrol.readByte(PlcMesObject.getPlcAddressBegin(), PlcMesObject.getPlcAddressLength());
            if(getplcvlues!=null) {
                PlcMesObject.setPlcParameterList(getplcvlues);
            }
        }
    }
}