From 435476e0f0162f8cdeda311937728c52c04ffbcb Mon Sep 17 00:00:00 2001
From: zhoushihao <zsh19950802@163.com>
Date: 星期三, 08 五月 2024 11:03:53 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
/dev/null | 195 --------------------------------
hangzhoumesParent/moduleService/CacheGlassModule/src/main/resources/JsonFile/PlcCacheGlass.json | 57 +++++++++
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcHomeEdg.java | 12 -
hangzhoumesParent/common/servicebase/src/main/java/com/mes/device/PlcParameterInfo.java | 9
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/S7object.java | 28 ++++
hangzhoumesParent/common/servicebase/src/main/java/com/mes/device/PlcParameterObject.java | 21 +++
6 files changed, 112 insertions(+), 210 deletions(-)
diff --git a/hangzhoumesParent/common/servicebase/src/main/java/com/mes/device/PlcParameterInfo.java b/hangzhoumesParent/common/servicebase/src/main/java/com/mes/device/PlcParameterInfo.java
index 15fa1e7..4969c73 100644
--- a/hangzhoumesParent/common/servicebase/src/main/java/com/mes/device/PlcParameterInfo.java
+++ b/hangzhoumesParent/common/servicebase/src/main/java/com/mes/device/PlcParameterInfo.java
@@ -105,9 +105,10 @@
if (addressLength < 2) {
return null;
}
+ int wordindex = index;
+ return stringdatas[0] + "." + wordindex;
+ /* if (addressLength == 2) {
- if (addressLength == 2) {
- int wordindex = index;
return stringdatas[0] + "." + wordindex;
}
@@ -115,8 +116,8 @@
int wordindex = index;
int newIndex = wordindex + 13;
return stringdatas[0] + "." + wordindex + "-" + newIndex;
- }
- return null;
+ }*/
+// return null;
}
public int getPlcAddress() {
diff --git a/hangzhoumesParent/common/servicebase/src/main/java/com/mes/device/PlcParameterObject.java b/hangzhoumesParent/common/servicebase/src/main/java/com/mes/device/PlcParameterObject.java
index 10a3b2f..2d34674 100644
--- a/hangzhoumesParent/common/servicebase/src/main/java/com/mes/device/PlcParameterObject.java
+++ b/hangzhoumesParent/common/servicebase/src/main/java/com/mes/device/PlcParameterObject.java
@@ -148,7 +148,10 @@
}
if (plcParameterInfo.getAddressLength() == 2) {
plcParameterInfo.setValue(String.valueOf(byte2short(valueList)));
- } else if (plcParameterInfo.getAddressLength() == 14) {
+ } else if (plcParameterInfo.getAddressLength() == 4) {
+ plcParameterInfo.setValue(String.valueOf(byte2int(valueList)));
+ }
+ else if (plcParameterInfo.getAddressLength() >10) {
plcParameterInfo.setValue((byteToHexString(valueList)));
} else {
String valuestr = new String(valueList);
@@ -186,9 +189,21 @@
return l;
}
+ /**
+ * byte[]绫诲瀷杞瑂hort
+ *
+ * @param b byte[]绫诲瀷鍊�
+ */
+ public static short byte2int(byte[] b) {
+ short l = 0;
+ for (int i = 0; i < 4; i++) {
+ l <<= 8; //<<=鍜屾垜浠殑 +=鏄竴鏍风殑锛屾剰鎬濆氨鏄� l = l << 8
+ l |= (b[3-i] & 0xff); //鍜屼笂闈篃鏄竴鏍风殑 l = l | (b[i]&0xff)
+ }
+ return l;
+ }
public static String byteToHexString(byte[] bytes) {
-
- String str = new String(bytes, StandardCharsets.UTF_8);
+ String str = new String(bytes, StandardCharsets.UTF_8).trim();
return str;
}
diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/InitUtil.java b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/InitUtil.java
deleted file mode 100644
index 33fd9ea..0000000
--- a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/InitUtil.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package com.mes.common;
-import cn.hutool.json.JSONArray;
-import cn.hutool.json.JSONObject;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-
-public class InitUtil {
- //鍒濆鍖杦ord
- public static PlcParameterObject initword(String jsonFilePath) {
- try {
- FileReader fileReader = new FileReader(jsonFilePath);
- BufferedReader bufferedReader = new BufferedReader(fileReader);
-
- StringBuilder content = new StringBuilder();
- String line;
-
- while ((line = bufferedReader.readLine()) != null) {
- content.append(line);
- }
-
- bufferedReader.close();
- fileReader.close();
-
- JSONObject jsonfileobj = new JSONObject(content.toString());
- JSONArray jsonArray = jsonfileobj.getJSONArray("parameteInfor");
- PlcParameterObject plcParameterObject = new PlcParameterObject();
- plcParameterObject.setPlcAddressBegin(jsonfileobj.getStr("plcAddressBegin"));//璁剧疆璧峰浣嶅湴鍧�
- plcParameterObject.setPlcAddressLength(Integer.valueOf(jsonfileobj.getStr("plcAddressLenght")));//璁剧疆鍦板潃闀垮害
-
- for (int i = 0; i < jsonArray.size(); i++) {
- JSONObject parameterObj = jsonArray.getJSONObject(i);
- PlcParameterInfo plcParameterInfo = new PlcParameterInfo(jsonfileobj.getStr("plcAddressBegin")); //鍙傛暟瀹炰緥
- String codeid = parameterObj.getStr("codeId");
- plcParameterInfo.setCodeId(codeid);
- plcParameterInfo.setAddressIndex(Integer.valueOf(parameterObj.getStr("addressIndex")));
- //plcParameterInfo.setRatio(Integer.valueOf(parameterObj.getStr("ratio")));
- plcParameterInfo.setAddressLength(Integer.valueOf(parameterObj.getStr("addressLenght")));
- plcParameterInfo.setUnit(parameterObj.getStr("unit"));
- plcParameterObject.addPlcParameter(plcParameterInfo);
- }
- // byte[] getplcvlues = {0x01, 0x02, 0x03, 0x04,0x01, 0x02, 0x03, 0x04,0x01, 0x02, 0x03, 0x04,0x01, 0x02,0x01, 0x02, 0x03, 0x04,0x01, 0x02, 0x03, 0x04,0x01, 0x02, 0x03, 0x04,0x01, 0x02,0x01, 0x02, 0x03, 0x04,0x01, 0x02, 0x03, 0x04,0x01, 0x02, 0x03, 0x04,0x01, 0x02};
- // byte[] getplcvlues = S7control.getinstance().ReadByte(plcParameterObject.getPlcAddressBegin(), plcParameterObject.getPlcAddressLength());
- // plcParameterObject.setPlcParameterList(getplcvlues);
-
- return plcParameterObject;
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- //鍒濆鍖朾it
- public static PlcBitObject initbit(String jsonFilePath) {
- PlcBitObject plcBitObject = new PlcBitObject();
-
- try {
- FileReader fileReader = new FileReader(jsonFilePath);
- BufferedReader bufferedReader = new BufferedReader(fileReader);
-
- StringBuilder content = new StringBuilder();
- String line;
-
- while ((line = bufferedReader.readLine()) != null) {
- content.append(line);
- }
-
- bufferedReader.close();
- fileReader.close();
-
- JSONObject jsonfileobj = new JSONObject(content.toString());
- JSONArray jsonArray = jsonfileobj.getJSONArray("parameteInfor");
- plcBitObject.setPlcAddressBegin(jsonfileobj.getStr("plcAddressBegin"));//璁剧疆璧峰浣嶅湴鍧�
- plcBitObject.setPlcAddressLength(Integer.valueOf(jsonfileobj.getStr("plcAddressLenght")));//璁剧疆鍦板潃闀垮害
-
- for (int i = 0; i < jsonArray.size(); i++) {
- JSONObject parameterObj = jsonArray.getJSONObject(i);
-
- PlcBitInfo plcBitInfo = new PlcBitInfo(jsonfileobj.getStr("plcAddressBegin")); //鍙傛暟瀹炰緥
- String codeid = parameterObj.getStr("codeId");
- plcBitInfo.setCodeId(codeid);
- plcBitInfo.setAddressIndex(Integer.valueOf(parameterObj.getStr("addressIndex")));
-
- plcBitObject.addPlcBit(plcBitInfo);
- }
- System.out.println("");
- } catch (IOException e) {
- e.printStackTrace();
- }
- //Boolean[] values1 = { false, true, true, true, false, false, true, false,
- // false, true ,true };
- // List<Boolean> getplcvlues = new ArrayList<>(Arrays.asList(values1));
-
-// List<Boolean> getplcvlues = S7control.getinstance().ReadBits(plcBitObject.getPlcAddressBegin(), plcBitObject.getPlcAddressLength());
-// plcBitObject.setPlcBitList(getplcvlues);
- return plcBitObject;
- }
-
-//
- public static void readAndUpdateBitValues(PlcBitObject plcBitObject) {
-
-// Boolean[] values1 = { false, true, true, true, false, false, true, false,
-// false, true ,true };
-// List<Boolean> getplcvlues = new ArrayList<>(Arrays.asList(values1));
-// List<Boolean> getplcvlues = S7object.getinstance().plccontrol.ReadBits(plcBitObject.getPlcAddressBegin(), plcBitObject.getPlcAddressLength());
-// plcBitObject.setPlcBitList(getplcvlues);
- }
-
-
- public static void readAndUpdateWordValues(PlcParameterObject plcParameterObject) {
-
- // byte[] getplcvlues = {0x01, 0x02, 0x03, 0x04,0x01, 0x02, 0x03, 0x04,0x01, 0x02, 0x03, 0x04,0x01, 0x02,0x01, 0x02, 0x03, 0x04,0x01, 0x02, 0x03, 0x04,0x01, 0x02, 0x03, 0x04,0x01, 0x02,0x01, 0x02, 0x03, 0x04,0x01, 0x02, 0x03, 0x04,0x01, 0x02, 0x03, 0x04,0x01, 0x02};
-// byte[] getplcvlues = S7object.getinstance().plccontrol.ReadByte(plcParameterObject.getPlcAddressBegin(), plcParameterObject.getPlcAddressLength());
-// plcParameterObject.setPlcParameterList(getplcvlues);
- }
-
-
-
-}
diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/JsonFile/PlcCacheGlass.json b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/JsonFile/PlcCacheGlass.json
deleted file mode 100644
index eed5688..0000000
--- a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/JsonFile/PlcCacheGlass.json
+++ /dev/null
@@ -1,414 +0,0 @@
-{
- "plcAddressBegin":"DB14.0",
- "plcAddressLenght":"208",
- "dataType":"word",
- "parameteInfor":[
- {
- "codeId": "PLCToMES",
- "addressIndex":"0",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"m/min"
- },
- {
- "codeId": "IDStatus1",
- "addressIndex":"2",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"m/min"
- },
- {
- "codeId": "IDStatus2",
- "addressIndex":"4",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"m/min"
- },
- {
- "codeId": "IDStatus3",
- "addressIndex":"6",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },
- {
- "codeId": "IDStatus4",
- "addressIndex":"8",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },
- {
- "codeId": "IDStatus5",
- "addressIndex":"10",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- }
- ,
- {
- "codeId": "IDStatus6",
- "addressIndex":"12",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },
- {
- "codeId": "StautsID1",
- "addressIndex":"14",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- }
- ,
- {
- "codeId": "StautsID2",
- "addressIndex":"16",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- }
- ,
- {
- "codeId": "StautsID3",
- "addressIndex":"18",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- }
- ,
- {
- "codeId": "StautsID4",
- "addressIndex":"20",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- }
- ,
- {
- "codeId": "StautsID5",
- "addressIndex":"22",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },
- {
- "codeId": "StautsID6",
- "addressIndex":"24",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },
- {
- "codeId": "GaToMES",
- "addressIndex":"26",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },
- {
- "codeId": "Height",
- "addressIndex":"28",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },
- {
- "codeId": "width",
- "addressIndex":"30",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },
- {
- "codeId": "ExportTOMES1",
- "addressIndex":"32",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- }
- ,
- {
- "codeId": "ExportToMES2",
- "addressIndex":"34",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- } ,
- {
- "codeId": "MESToPLC",
- "addressIndex":"36",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- } ,
- {
- "codeId": "MESID1",
- "addressIndex":"38",
- "addressLenght":"14",
- "ratio":"1",
- "unit":"mm/S"
- } ,
- {
- "codeId": "MESID2",
- "addressIndex":"54",
- "addressLenght":"14",
- "ratio":"1",
- "unit":"mm/S"
- },
- {
- "codeId": "MESID3",
- "addressIndex":"70",
- "addressLenght":"14",
- "ratio":"1",
- "unit":"mm/S"
- },
- {
- "codeId": "MESID4",
- "addressIndex":"86",
- "addressLenght":"14",
- "ratio":"1",
- "unit":"mm/S"
- },
- {
- "codeId": "MESID5",
- "addressIndex":"102",
- "addressLenght":"14",
- "ratio":"1",
- "unit":"mm/S"
- },
- {
- "codeId": "MESID6",
- "addressIndex":"118",
- "addressLenght":"14",
- "ratio":"1",
- "unit":"mm/S"
- },
- {
- "codeId": "MESToPLCStart1",
- "addressIndex":"134",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCStart2",
- "addressIndex":"136",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCStart3",
- "addressIndex":"138",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- }
- ,{
- "codeId": "MESToPLCStart4",
- "addressIndex":"140",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- }
- ,{
- "codeId": "MESToPLCStart5",
- "addressIndex":"142",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- }
- ,{
- "codeId": "MESToPLCStart6",
- "addressIndex":"144",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCTarget1",
- "addressIndex":"146",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCTarget2",
- "addressIndex":"148",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCTarget3",
- "addressIndex":"150",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCTarget4",
- "addressIndex":"152",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCTarget5",
- "addressIndex":"154",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCTarget6",
- "addressIndex":"156",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCStatus1",
- "addressIndex":"158",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCStatus2",
- "addressIndex":"160",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCStatus3",
- "addressIndex":"162",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCStatus4",
- "addressIndex":"164",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCStatus5",
- "addressIndex":"166",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToPLCStatus6",
- "addressIndex":"168",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "MESToGaStatus",
- "addressIndex":"170",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "A01Err",
- "addressIndex":"172",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "A02Err",
- "addressIndex":"174",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "B01Err",
- "addressIndex":"176",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "C01Err",
- "addressIndex":"178",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "C02Err",
- "addressIndex":"180",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "ErrSpace1",
- "addressIndex":"182",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "ErrSpace2",
- "addressIndex":"184",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "ErrSpace3",
- "addressIndex":"186",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "B01Position",
- "addressIndex":"188",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "C01Position",
- "addressIndex":"190",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "C02Position",
- "addressIndex":"192",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "DeviceState",
- "addressIndex":"194",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "AllFVRun",
- "addressIndex":"196",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "A01State",
- "addressIndex":"198",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "A02State",
- "addressIndex":"200",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "B01State",
- "addressIndex":"202",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "C01State",
- "addressIndex":"204",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- },{
- "codeId": "C02State",
- "addressIndex":"206",
- "addressLenght":"2",
- "ratio":"1",
- "unit":"mm/S"
- }
- ]
-}
diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PLCAutoMes.java b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PLCAutoMes.java
deleted file mode 100644
index 4e8fe38..0000000
--- a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PLCAutoMes.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.mes.common;
-
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-
-import static com.mes.common.InitUtil.readAndUpdateWordValues;
-
-public class PLCAutoMes extends Thread {
-
- private static final Logger log = LoggerFactory.getLogger(PLCAutoMes.class);
- private static InitUtil initUtil;
-
- // 鍗曚緥瀹炰緥
- private static PLCAutoMes instance;
- private static String PlcAlbania;
-
-
-
- public static PlcParameterObject PlcMesObject;
-
- // 绉佹湁鏋勯�犲嚱鏁�
- public PLCAutoMes() throws IOException {
- PlcAlbania="D:\\SQL\\PlcCacheGlass.json";
-// PlcAlbania=PLCAutoMes.class.getResource("/JsonFile/PlcCacheGlass.json").getPath();
- //log.info(PLCAutoMes.class.getResource("").getPath());
- PlcMesObject = InitUtil.initword(PlcAlbania);
- 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(100);
-
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- readAndUpdateWordValues(PlcMesObject);
-
-
- }
- }
-}
diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcBitInfo.java b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcBitInfo.java
deleted file mode 100644
index fe3439d..0000000
--- a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcBitInfo.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.mes.common;
-
-
-public class PlcBitInfo {
-
- public PlcBitInfo(String startAddress) {
- this.startAddress = startAddress;
- }
-
- private String startAddress;
- // 鍙傛暟鏍囪瘑
- private String codeId;
-
- // 鍙傛暟鍚嶇О
- private String name;
-
- // 璇诲彇 鍙傛暟鍊�
- private Boolean value;
- // 鍙傛暟鍦板潃
- private int addressIndex;
-
- public String getCodeId() {
- return this.codeId;
- }
-
- public void setCodeId(String codeId) {
- this.codeId = codeId;
- }
-
- public String getName() {
- return this.name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Boolean getValue() {
- return this.value;
- }
-
- public void setValue(Boolean value) {
- this.value = value;
- }
-
-
- public int getAddressIndex() {
- return this.addressIndex;
- }
-
- /**
- * 鑾峰彇鍦板潃
- *
- * @param index 绱㈠紩鍦板潃
- */
- public String getAddress(int index) {
- String[] stringdatas = this.startAddress.trim().split("\\.");
- if (stringdatas.length < 2)
- return null;
- int dbwindex = 0;
- int bitindex = 0;
- if (stringdatas.length == 3) {
- dbwindex = Integer.parseInt(stringdatas[1]);
- bitindex = Integer.parseInt(stringdatas[2]);
- } else
- return null;
- dbwindex += index / 8;
- bitindex += index % 8;
- return stringdatas[0] + "." + dbwindex + "." + bitindex;
- }
-
-
- public void setAddressIndex(int addressindex) {
- this.addressIndex = addressindex;
- }
-}
diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcBitObject.java b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcBitObject.java
deleted file mode 100644
index 4bd20de..0000000
--- a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcBitObject.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package com.mes.common;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-public class PlcBitObject {
-
- // 璇ユā鍧楁暟鎹被鍨嬶紝鏁版嵁璧峰浣嶇疆
- private String plcAddressBegin;
- // 鏁版嵁鍦板潃闀垮害锛氱涓�鍙傛暟鍒版渶鍚庝竴涓弬鏁扮殑闀垮害
- private int plcAddressLength;
- private ArrayList<PlcBitInfo> plcBitList;
-
- /**
- * @return 鏁版嵁鍖哄紑濮嬪湴鍧�
- */
- public String getPlcAddressBegin() {
- return plcAddressBegin;
- }
-
- /**
- * @param plcAddressBegin 璁剧疆鏁版嵁鍖哄紑濮嬪湴鍧�
- */
- public void setPlcAddressBegin(String plcAddressBegin) {
- this.plcAddressBegin = plcAddressBegin;
- }
-
- /**
- * @return 鏁版嵁鍖� 璇诲彇鎵�鏈夋暟鎹墍闇�鐨勯暱搴︼紙浠yte绫诲瀷涓哄熀鍑嗭級
- */
- public int getPlcAddressLength() {
- return plcAddressLength;
- }
-
- /**
- * @return 璁剧疆锛氭暟鎹尯 璇诲彇鎵�鏈夋暟鎹墍闇�鐨勯暱搴︼紙浠yte绫诲瀷涓哄熀鍑嗭級
- */
- public void setPlcAddressLength(int plcAddressLength) {
- this.plcAddressLength = plcAddressLength;
- }
-
- /**
- * @return 鑾峰彇鍙傛暟瀹炰緥闆嗗悎
- */
- public ArrayList<PlcBitInfo> getBitList() {
- return plcBitList;
- }
-
- /**
- * 鏍规嵁鍙傛暟鏍囪瘑 鑾峰彇鏌愪釜鍙傛暟瀹炰緥
- *
- * @param codeid 鍙傛暟鏍囪瘑
- * @return 鑾峰彇鏌愪釜鍙傛暟瀹炰緥
- */
- public PlcBitInfo getPlcBit(String codeid) {
- if (plcBitList != null) {
- for (PlcBitInfo plcbitInfo : plcBitList) {
- if (plcbitInfo.getCodeId().equals(codeid))
- return plcbitInfo;
- }
- return null;
- } else
- return null;
- }
-
- /**
- * 鏍规嵁鍙傛暟鏍囪瘑 鑾峰彇鏌愪釜鍙傛暟瀹炰緥
- *
- * @param codeid 鍙傛暟鏍囪瘑
- * @return 鑾峰彇鏌愪釜鍙傛暟瀹炰緥
- */
- public List<Boolean> getPlcBitValues(List<String> codeids) {
- List<Boolean> arrayList = new ArrayList<>();
- if (plcBitList != null) {
- Map<String, Boolean> resultMap = new LinkedHashMap<>(); // 浣跨敤 LinkedHashMap 淇濈暀鎻掑叆椤哄簭
- for (PlcBitInfo plcBitInfo : plcBitList) {
- if (codeids.contains(plcBitInfo.getCodeId().toString())) {
- resultMap.put(plcBitInfo.getCodeId().toString(), plcBitInfo.getValue());
- }
- }
- for (String codeId : codeids) { // 鎸夌収浼犲叆鍙傛暟鐨勯『搴忛亶鍘�
- Boolean value = resultMap.get(codeId);
- if (value != null) {
- arrayList.add(value);
- } else {
- arrayList.add(null); // 濡傛灉鎵句笉鍒板搴旂殑鍊硷紝娣诲姞 null
- }
- }
- }
- return arrayList;
- }
-
-
- public List<String> getAddressListByCodeId(List<String> codeIdList) {
- List<String> addressList = new ArrayList<>();
- for (String codeId : codeIdList) {
- for (PlcBitInfo plcBitInfo : plcBitList) {
- if (plcBitInfo.getCodeId().equals(codeId)) {
- int index = plcBitInfo.getAddressIndex();
- String address = plcBitInfo.getAddress(index);
- if (address != null) {
- addressList.add(address);
- }
- }
- }
- }
- return addressList;
- }
-
-
- /**
- * 娣诲姞鍙傛暟瀹炰緥
- *
- * @param param 鍙傛暟瀹炰緥
- */
- public void addPlcBit(PlcBitInfo param) {
- if (plcBitList != null)
- plcBitList.add(param);
- else {
- plcBitList = new ArrayList<PlcBitInfo>();
- plcBitList.add(param);
- }
- }
-
- /**
- * 鏍规嵁PLC杩斿洖鐨勬暟鎹� 缁欏弬鏁板疄渚嬭祴鍊�
- *
- * @param plcValueArray PLC璇诲彇鍥炴潵鐨刡yte绫诲瀷鏁版嵁闆嗗悎
- */
- public void setPlcBitList(List<Boolean> plcValueArray) {
- if (plcBitList != null) {
- for (PlcBitInfo plcbitInfo : plcBitList) {
- plcbitInfo.setValue(plcValueArray.get(plcbitInfo.getAddressIndex()));
- }
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcHomeEdg.java b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcHomeEdg.java
index 08b144c..8ca8e6d 100644
--- a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcHomeEdg.java
+++ b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcHomeEdg.java
@@ -153,18 +153,16 @@
}
mapValue.put(key, value);
}
+
+ S7object.getinstance().plccontrol.WriteWord(S7object.getinstance().PlcMesObject.getPlcParameter("A06_request_word").getAddress(), (short)1);
try {
Thread.sleep(1000);
- taskCacheService = WebSocketServer.applicationContext.getBean(TaskCacheService.class);
- glassInfoService = WebSocketServer.applicationContext.getBean(GlassInfoService.class);
- edgStorageCageService = WebSocketServer.applicationContext.getBean(EdgStorageCageService.class);
- edgStorageCageDetailsMapper = WebSocketServer.applicationContext.getBean(EdgStorageCageDetailsMapper.class);
// initialize();//鍒濆鍖栨暟鎹�
- if ("0".equals(mapValue.get("A06_request_word"))) {
+ if ("0".equals(S7object.getinstance().PlcMesObject.getPlcParameter("A06_request_word"))) {
//娓呴櫎
S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"), (short) 0);
- } else if ("1".equals(mapValue.get("A06_request_word")) &&
- "0".equals(mapValue.get("MES_confirmation_word"))) {
+ } else if ("1".equals(S7object.getinstance().PlcMesObject.getPlcParameter("A06_request_word")) &&
+ "0".equals(S7object.getinstance().PlcMesObject.getPlcParameter("MES_confirmation_word"))) {
inTo();
} else if ("2".equals(mapValue.get("A06_request_word")) &&
diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcParameterInfo.java b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcParameterInfo.java
deleted file mode 100644
index c4d17af..0000000
--- a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcParameterInfo.java
+++ /dev/null
@@ -1,131 +0,0 @@
-package com.mes.common;
-
-public class PlcParameterInfo {
- public PlcParameterInfo(String startAddress) {
- this.startAddress = startAddress;
- }
-
- private String startAddress;
- // 鍙傛暟鏍囪瘑
- private String codeId;
-
- // 鍙傛暟鍚嶇О
- private String name;
-
- // 璇诲彇 鍙傛暟鍊�
- private String value;
-
- // // 鍐欏叆 鍙傛暟鍊�
- // private String writeValue;
-
- // 鍙傛暟鍗曚綅
- private String unit;
-
- // 鍙傛暟鍊艰浆鎹㈢郴鏁�
- private int ratio;
-
- // 鍙傛暟鍦板潃
- private int addressIndex;
-
- // 鍙傛暟鍦板潃浣嶉暱搴�
- private int addressLength;
-
- public String getCodeId() {
- return this.codeId;
- }
-
- public void setCodeId(String codeId) {
- this.codeId = codeId;
- }
-
- public String getName() {
- return this.name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getValue() {
- return this.value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- // public String getWriteValue() {
- // return this.writeValue;
- // }
-
- // public void setWriteValue(String writeValue) {
- // this.writeValue = writeValue;
- // }
-
- public String getUnit() {
- return this.unit;
- }
-
- public void setUnit(String unit) {
- this.unit = unit;
- }
-
- public int getAddressIndex() {
- return this.addressIndex;
- }
-
- public void setAddressIndex(int addressindex) {
- this.addressIndex = addressindex;
- }
-
- public int getAddressLength() {
- return this.addressLength;
- }
-
- public void setAddressLength(int addresslength) {
- this.addressLength = addresslength;
- }
-
- public int getRatio() {
- return this.ratio;
- }
-
- public void setRatio(int ratio) {
- this.ratio = ratio;
- }
-
-
- /**
- * 鑾峰彇鍦板潃
- *
- * @param index 绱㈠紩鍦板潃
- */
- public String getAddress(int index) {
- String[] stringdatas = this.startAddress.trim().split("\\.");
- int addressLength = this.addressLength;
- if (addressLength < 2) {
- return null;
- }
-
- if (addressLength == 2) {
- int wordindex = index;
-
- return stringdatas[0] + "." + wordindex;
- }
- if (addressLength == 14) {
- int wordindex = index;
- //int newIndex = wordindex + 13;
- return stringdatas[0] + "." + wordindex;
- }
- return null;
- }
-
- public int getPlcAddress() {
-
- return addressIndex;
- }
-
- public String getAddress() {
- return getAddress(this.addressIndex);
- }
-}
\ No newline at end of file
diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcParameterObject.java b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcParameterObject.java
deleted file mode 100644
index e06fc12..0000000
--- a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcParameterObject.java
+++ /dev/null
@@ -1,195 +0,0 @@
-package com.mes.common;
-
-import java.lang.reflect.Array;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-public class PlcParameterObject {
-
- // 璇ユā鍧楁暟鎹被鍨嬶紝鏁版嵁璧峰浣嶇疆
- private String plcAddressBegin;
- // 鏁版嵁鍦板潃闀垮害锛氱涓�鍙傛暟鍒版渶鍚庝竴涓弬鏁扮殑闀垮害
- private int plcAddressLength;
- private ArrayList<PlcParameterInfo> plcParameterList;
-
- /**
- * @return 鏁版嵁鍖哄紑濮嬪湴鍧�
- */
- public String getPlcAddressBegin() {
- return plcAddressBegin;
- }
-
- /**
- * @param plcAddressBegin 璁剧疆鏁版嵁鍖哄紑濮嬪湴鍧�
- */
- public void setPlcAddressBegin(String plcAddressBegin) {
- this.plcAddressBegin = plcAddressBegin;
- }
-
- /**
- * @return 鏁版嵁鍖� 璇诲彇鎵�鏈夋暟鎹墍闇�鐨勯暱搴︼紙浠yte绫诲瀷涓哄熀鍑嗭級
- */
- public int getPlcAddressLength() {
- return plcAddressLength;
- }
-
- /**
- * @return 璁剧疆锛氭暟鎹尯 璇诲彇鎵�鏈夋暟鎹墍闇�鐨勯暱搴︼紙浠yte绫诲瀷涓哄熀鍑嗭級
- */
- public void setPlcAddressLength(int plcAddressLength) {
- this.plcAddressLength = plcAddressLength;
- }
-
- /**
- * @return 鑾峰彇鍙傛暟瀹炰緥闆嗗悎
- */
- public ArrayList<PlcParameterInfo> getPlcParameterList() {
- return plcParameterList;
- }
-
- /**
- * 鏍规嵁鍙傛暟鏍囪瘑 鑾峰彇鏌愪釜鍙傛暟瀹炰緥
- *
- * @param codeid 鍙傛暟鏍囪瘑
- * @return 鑾峰彇鏌愪釜鍙傛暟瀹炰緥
- */
- public PlcParameterInfo getPlcParameter(String codeid) {
- if (plcParameterList != null) {
- for (PlcParameterInfo plcParameterInfo : plcParameterList) {
- if (plcParameterInfo.getCodeId().equals(codeid))
- return plcParameterInfo;
- }
- return null;
- } else
- return null;
- }
-
-
- /**
- * 鏍规嵁鍙傛暟鏍囪瘑 鑾峰彇鏌愪釜鍙傛暟瀹炰緥
- *
- * @param codeids 鍙傛暟鏍囪瘑
- * @return 鑾峰彇鏌愪釜鍙傛暟瀹炰緥
- */
- public List<String> getPlcParameterValues(List<String> codeids) {
- List<String> arrayList = new ArrayList<>();
- if (plcParameterList != null) {
- Map<String, PlcParameterInfo> resultMap = new LinkedHashMap<>(); // 浣跨敤 LinkedHashMap 淇濈暀鎻掑叆椤哄簭
- for (PlcParameterInfo plcParameterInfo : plcParameterList) {
- if (codeids.contains(plcParameterInfo.getCodeId())) {
- resultMap.put(plcParameterInfo.getCodeId(), plcParameterInfo);
- }
- }
- for (String codeId : codeids) { // 鎸夌収浼犲叆鍙傛暟鐨勯『搴忛亶鍘�
- PlcParameterInfo plcParameterInfo = resultMap.get(codeId);
- if (plcParameterInfo != null) {
- arrayList.add(plcParameterInfo.getValue());
- } else {
- arrayList.add(null); // 濡傛灉鎵句笉鍒板搴旂殑鍊硷紝娣诲姞 null
- }
- }
- }
- return arrayList;
- }
-
-
- public List<String> getAddressListByCodeId(List<String> codeIdList) {
- List<String> addressList = new ArrayList<>();
- for (String codeId : codeIdList) {
- for (PlcParameterInfo plcParameterInfo : plcParameterList) {
- if (plcParameterInfo.getCodeId().equals(codeId)) {
- int index = plcParameterInfo.getAddressIndex();
- String address = plcParameterInfo.getAddress(index);
- if (address != null) {
- addressList.add(address);
- }
- }
- }
- }
- return addressList;
- }
-
-
- /**
- * 娣诲姞鍙傛暟瀹炰緥
- *
- * @param param 鍙傛暟瀹炰緥
- */
- public void addPlcParameter(PlcParameterInfo param) {
- if (plcParameterList != null)
- plcParameterList.add(param);
- else {
- plcParameterList = new ArrayList<PlcParameterInfo>();
- plcParameterList.add(param);
- }
- }
-
- /**
- * 鏍规嵁PLC杩斿洖鐨勬暟鎹� 缁欏弬鏁板疄渚嬭祴鍊�
- *
- * @param plcValueArray PLC璇诲彇鍥炴潵鐨刡yte绫诲瀷鏁版嵁闆嗗悎
- */
- public void setPlcParameterList(byte[] plcValueArray) {
- if (plcParameterList != null) {
-
- for (PlcParameterInfo plcParameterInfo : plcParameterList) {
-
- byte[] valueList = new byte[plcParameterInfo.getAddressLength()];
-
-// System.out.println(plcParameterInfo.getAddressLength());
-
- for (int i = 0; i < plcParameterInfo.getAddressLength(); i++) {
- Array.setByte(valueList, i, plcValueArray[plcParameterInfo.getAddressIndex() + i]);
-
- }
- if (plcParameterInfo.getAddressLength() == 2) {
- plcParameterInfo.setValue(String.valueOf(byte2short(valueList)));
- } else if (plcParameterInfo.getAddressLength() == 14) {
- plcParameterInfo.setValue((byteToHexString(valueList)));
- } else {
- String valuestr = new String(valueList);
- plcParameterInfo.setValue(valuestr);
- }
- }
- }
- }
-
- /**
- * short绫诲瀷杞琤yte[]
- *
- * @param s short绫诲瀷鍊�
- */
- public static byte[] short2byte(short s) {
- byte[] b = new byte[2];
- for (int i = 0; i < 2; i++) {
- int offset = 16 - (i + 1) * 8; //鍥犱负byte鍗�4涓瓧鑺傦紝鎵�浠ヨ璁$畻鍋忕Щ閲�
- b[i] = (byte) ((s >> offset) & 0xff); //鎶�16浣嶅垎涓�2涓�8浣嶈繘琛屽垎鍒瓨鍌�
- }
- return b;
- }
-
- /**
- * byte[]绫诲瀷杞瑂hort
- *
- * @param b byte[]绫诲瀷鍊�
- */
- public static short byte2short(byte[] b) {
- short l = 0;
- for (int i = 0; i < 2; i++) {
- l <<= 8; //<<=鍜屾垜浠殑 +=鏄竴鏍风殑锛屾剰鎬濆氨鏄� l = l << 8
- l |= (b[i] & 0xff); //鍜屼笂闈篃鏄竴鏍风殑 l = l | (b[i]&0xff)
- }
- return l;
- }
-
- public static String byteToHexString(byte[] bytes) {
-
- String str = new String(bytes, StandardCharsets.UTF_8);
- return str;
- }
-
-
-}
\ No newline at end of file
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
index 2929123..de9760b 100644
--- a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/S7object.java
+++ b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/S7object.java
@@ -1,24 +1,34 @@
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.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);
}
}
@@ -33,4 +43,20 @@
}
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);
+
+ }
+ }
}
diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/resources/JsonFile/PlcCacheGlass.json b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/resources/JsonFile/PlcCacheGlass.json
new file mode 100644
index 0000000..0e9ca40
--- /dev/null
+++ b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/resources/JsonFile/PlcCacheGlass.json
@@ -0,0 +1,57 @@
+{
+ "plcAddressBegin":"DB14.0",
+ "plcAddressLenght":"80",
+ "dataType":"word",
+ "parameteInfor":[
+ {
+ "codeId": "A06_request_word",
+ "addressIndex":"0",
+ "addressLenght":"2",
+ "ratio":"1",
+ "unit":"m/min"
+ },
+ {
+ "codeId": "A05_scanning_ID",
+ "addressIndex":"2",
+ "addressLenght":"30",
+ "ratio":"1",
+ "unit":""
+ },
+ {
+ "codeId": "MES_confirmation_word",
+ "addressIndex":"40",
+ "addressLenght":"2",
+ "ratio":"1",
+ "unit":""
+ },
+ {
+ "codeId": "A09_glass_status",
+ "addressIndex":"70",
+ "addressLenght":"2",
+ "ratio":"1",
+ "unit":""
+ },
+ {
+ "codeId": "A10_glass_status",
+ "addressIndex":"72",
+ "addressLenght":"2",
+ "ratio":"1",
+ "unit":""
+ },
+ {
+ "codeId": "A09_prohibit_film_production",
+ "addressIndex":"74",
+ "addressLenght":"2",
+ "ratio":"1",
+ "unit":""
+ }
+ ,
+ {
+ "codeId": "A10_prohibit_film_production",
+ "addressIndex":"76",
+ "addressLenght":"2",
+ "ratio":"1",
+ "unit":""
+ }
+ ]
+}
--
Gitblit v1.8.0