From 9a0dd8244282d90b08b16d2c239683bbac62fab2 Mon Sep 17 00:00:00 2001 From: ZengTao <2773468879@qq.com> Date: 星期二, 16 一月 2024 15:02:21 +0800 Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/CanadaMes --- springboot-vue3/src/main/java/com/example/springboot/entity/device/PlcParameterObject.java | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 169 insertions(+), 0 deletions(-) diff --git a/springboot-vue3/src/main/java/com/example/springboot/entity/device/PlcParameterObject.java b/springboot-vue3/src/main/java/com/example/springboot/entity/device/PlcParameterObject.java new file mode 100644 index 0000000..56a0230 --- /dev/null +++ b/springboot-vue3/src/main/java/com/example/springboot/entity/device/PlcParameterObject.java @@ -0,0 +1,169 @@ +package com.example.springboot.entity.device; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.List; + +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 codeid 鍙傛暟鏍囪瘑 + * @return 鑾峰彇鏌愪釜鍙傛暟瀹炰緥 + */ + public List<String> getPlcParameterValues(List<String> codeids) { + List<String> arrayList = new ArrayList(); + if (plcParameterList != null) { + for (PlcParameterInfo plcParameterInfo : plcParameterList) { + if (codeids.contains(plcParameterInfo.getCodeId().toString())) + arrayList.add(plcParameterInfo.getValue()); + } + } + return arrayList; + } + + + public List<String> getPlcAddressList(String codeid) { + List<String> addressList = new ArrayList<>(); + if (plcParameterList != null) { + for (PlcParameterInfo plcParameterInfo : plcParameterList) { + if (plcParameterInfo.getCodeId().equals(codeid)) { + int plcAddress = plcParameterInfo.getPlcAddress(); + if (!addressList.contains(plcAddress)) { + addressList.add(String.valueOf(plcAddress)); + } + } + } + } + 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()]; + 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 + { + 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; + } + + +} \ No newline at end of file -- Gitblit v1.8.0