From d3c0031291fd18d6aaaea05b7e4bb866f1e371ba Mon Sep 17 00:00:00 2001 From: liuhanqing Date: Wed, 24 Sep 2025 09:28:47 +0800 Subject: [PATCH] =?UTF-8?q?tools=20sendData=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/schedule/plcRead/util/Tools.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/schedule/plcRead/util/Tools.java b/ruoyi-admin/src/main/java/com/ruoyi/schedule/plcRead/util/Tools.java index b76525c5..060590b0 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/schedule/plcRead/util/Tools.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/schedule/plcRead/util/Tools.java @@ -1,6 +1,7 @@ package com.ruoyi.schedule.plcRead.util; import HslCommunication.BasicFramework.SoftBasic; +import com.ruoyi.common.domain.SendData; import java.io.Serializable; import java.nio.charset.StandardCharsets; @@ -359,6 +360,29 @@ public class Tools implements Serializable { return df.format(t); } + /** + * 下发到PLC的反馈字节 + */ + public static byte[] sendData(SendData... list) { + byte[][] values = new byte[list.length][0]; + for (int i = 0; i < list.length; i++) { + byte[] bytes = Tools.intToBytes(list[i].getNum2(), list[i].getNum()); + //System.out.println(bytes.length); + values[i] = bytes; + } + int length_byte = 0; + for (byte[] value : values) { + length_byte += value.length; + } + byte[] all_byte = new byte[length_byte]; + int countLength = 0; + for (byte[] b : values) { + System.arraycopy(b, 0, all_byte, countLength, b.length); + countLength += b.length; + } + return all_byte; + } + //int 转2字节 public static byte[] intbyte(int res) {///Java中10进制转byte[] byte[] targets = new byte[2];