From 3fdf3c82bc1ac5f5fdce0f841db7bdeacf75704c Mon Sep 17 00:00:00 2001 From: wuyouming666 <2265557248@qq.com> Date: 星期五, 26 一月 2024 13:53:34 +0800 Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/CanadaMes --- springboot-vue3/src/main/java/com/example/springboot/component/PLCAutoMes.java | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 90 insertions(+), 0 deletions(-) diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/PLCAutoMes.java b/springboot-vue3/src/main/java/com/example/springboot/component/PLCAutoMes.java new file mode 100644 index 0000000..6e6ef8a --- /dev/null +++ b/springboot-vue3/src/main/java/com/example/springboot/component/PLCAutoMes.java @@ -0,0 +1,90 @@ +package com.example.springboot.component; + +import com.example.springboot.entity.device.PlcBitObject; +import com.example.springboot.entity.device.PlcParameterObject; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static com.example.springboot.component.InitUtil.readAndUpdateBitValues; +import static com.example.springboot.component.InitUtil.readAndUpdateWordValues; + +public class PLCAutoMes extends Thread { + + // 鐢ㄤ簬瀛樺偍搴旂敤绋嬪簭鐨勯厤缃俊鎭� + private Configuration config; + private static InitUtil initUtil; + // 鍒涘缓涓�涓嚜瀹氫箟鐨� S7 鎺у埗鍣ㄦ秷鎭鐞嗗櫒瀵硅薄 + MessageHandler customS7Control = new MessageHandler(); + + // 鍗曚緥瀹炰緥 + private static PLCAutoMes instance; + + // 绉佹湁鏋勯�犲嚱鏁� + public PLCAutoMes() throws IOException { + config = new Configuration("config.properties"); + initUtil = new InitUtil(); + } + + // 鑾峰彇鍗曚緥瀹炰緥 + public static synchronized PLCAutoMes getInstance() throws IOException { + if (instance == null) { + instance = new PLCAutoMes(); + } + return instance; + } + + @Override + public void run() { + while (this != null) { + try { + Thread.sleep(1000); + + } catch (InterruptedException e) { + e.printStackTrace(); + } + + + + String jsonFilePath = PLCAutoMes.class.getResource("/JsonFile/PlcMes.json").getPath(); + + String jsonFilePath2 = PLCAutoMes.class.getResource("/JsonFile/PlcRead.json").getPath(); + // String jsonFilePath3 = PLCAutoMes.class.getResource("/JsonFile/Plcframe.json").getPath(); + // System.out.println(jsonFilePath); + + // 璋冪敤initword鏂规硶 + PlcParameterObject PlcMesObject= initUtil.initword(jsonFilePath); + // 璋冪敤initbit鏂规硶 + PlcParameterObject PlcReadObject= initUtil.initword(jsonFilePath2); + // // 璋冪敤initbit鏂规硶 + // PlcParameterObject PlcframeObject= initUtil.initword(jsonFilePath3); + readAndUpdateWordValues(PlcReadObject); + readAndUpdateWordValues(PlcMesObject); + // readAndUpdateWordValues(PlcframeObject); + + + + + // readAndUpdateWordValues(plcStateObject); + int index = PlcMesObject.getPlcParameter("AddStart").getAddressIndex(); + //System.out.println(index); + PlcMesObject.getPlcParameter("AddStart").getAddress(index); + //System.out.println(PlcMesObject.getPlcParameter("AddStart").getAddress(index)); + List<String> addresses = new ArrayList<>(); + addresses.add("FeedID"); + addresses.add("AddStart"); + //System.out.println(addresses); + //System.out.println(PlcMesObject.getPlcParameterValues(addresses)); + List<String> addresses2 = new ArrayList<>(); + addresses2.add("FeedID"); + addresses2.add("FeedCarStatus"); + + System.out.println(PlcReadObject.getPlcParameterValues(addresses2)); + + + + + } + } +} -- Gitblit v1.8.0