From f39fd71eedfd828e715d33356a8c38ffbe66eb1a Mon Sep 17 00:00:00 2001
From: wuyouming666 <2265557248@qq.com>
Date: 星期五, 24 五月 2024 15:28:09 +0800
Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/HangZhouMes

---
 hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/common/S7object.java |   75 ++++++++++++++++++++++++-------------
 1 files changed, 49 insertions(+), 26 deletions(-)

diff --git a/hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/common/S7object.java b/hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/common/S7object.java
index e5f4389..f5e434b 100644
--- a/hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/common/S7object.java
+++ b/hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/common/S7object.java
@@ -1,36 +1,59 @@
 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 S7control plccontrol; // PLC閫氳绫诲疄渚�
-//    private EPlcType plcType = EPlcType.S1500; // 瑗块棬瀛怭LC绫诲瀷
-//    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;
-//    }
-//}
+public class S7object extends Thread {
+    public S7control plccontrol; // PLC閫氳绫诲疄渚�
+    private EPlcType plcType = EPlcType.S200_SMART; // 瑗块棬瀛怭LC绫诲瀷
+    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);
+        }
+    }
+
+    // 鍗曚緥妯″紡 鑾峰彇绫荤殑鍞竴瀹炰緥
+    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