From 12ae82141c1d6ed1a55922aae128ccfefb5b35dd Mon Sep 17 00:00:00 2001
From: wu <731351411@qq.com>
Date: 星期三, 24 一月 2024 13:34:06 +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 |   36 ++++++++++++++++++++++++++++++++----
 1 files changed, 32 insertions(+), 4 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
index 5e5abc9..8808874 100644
--- 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
@@ -1,8 +1,11 @@
 package com.example.springboot.entity.device;
 
 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 {
 
@@ -73,11 +76,21 @@
      * @return 鑾峰彇鏌愪釜鍙傛暟瀹炰緥
      */
     public List<String> getPlcParameterValues(List<String> codeids) {
-        List<String> arrayList = new ArrayList();
+        List<String> arrayList = new ArrayList<>();
         if (plcParameterList != null) {
+            Map<String, PlcParameterInfo> resultMap = new LinkedHashMap<>(); // 浣跨敤 LinkedHashMap 淇濈暀鎻掑叆椤哄簭
             for (PlcParameterInfo plcParameterInfo : plcParameterList) {
-                if (codeids.contains(plcParameterInfo.getCodeId()))
+                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;
@@ -87,7 +100,7 @@
 
 
 
-     
+
     /**
      * 娣诲姞鍙傛暟瀹炰緥
      * 
@@ -111,12 +124,21 @@
         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);
@@ -152,5 +174,11 @@
        return l;
    }
 
-   
+    public static String byteToHexString(byte[] bytes) {
+
+        String str = new String(bytes, StandardCharsets.UTF_8);
+        return str;
+    }
+
+
 }
\ No newline at end of file

--
Gitblit v1.8.0