zhangyong
2024-05-08 8c8e78eac51fdc57942e1e348ba54d0116515408
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[]类型转short
     *
     * @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;
    }