From 93e36c526fe445c14d5fb19f3653f8a8e55e3a6c Mon Sep 17 00:00:00 2001 From: wang <3597712270@qq.com> Date: 星期四, 09 五月 2024 15:49:34 +0800 Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/HangZhouMes --- hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/S7object.java | 62 +++++++++++++++++++++++++++++++ 1 files changed, 62 insertions(+), 0 deletions(-) diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/S7object.java b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/S7object.java new file mode 100644 index 0000000..de9760b --- /dev/null +++ b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/S7object.java @@ -0,0 +1,62 @@ +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 extends Thread { + public S7control plccontrol; // PLC閫氳绫诲疄渚� + private EPlcType plcType = EPlcType.S1200; // 瑗块棬瀛怭LC绫诲瀷 + private String ip = "192.168.10.1"; // 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 PlcCacheGlass=S7object.class.getResource("/JsonFile/PlcCacheGlass.json").getPath(); + //log.info(PLCAutoMes.class.getResource("").getPath()); + PlcMesObject = InitUtil.initword(PlcCacheGlass); + } + } + + // 鍗曚緥妯″紡 鑾峰彇绫荤殑鍞竴瀹炰緥 + public static S7object getinstance() { + if (instance == null) { + synchronized (S7object.class) { + if (instance == null) { + instance = new S7object(); + } + } + } + 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()); + PlcMesObject.setPlcParameterList(getplcvlues); + + } + } +} -- Gitblit v1.8.0