tools sendData方法
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.ruoyi.schedule.plcRead.util;
|
package com.ruoyi.schedule.plcRead.util;
|
||||||
|
|
||||||
import HslCommunication.BasicFramework.SoftBasic;
|
import HslCommunication.BasicFramework.SoftBasic;
|
||||||
|
import com.ruoyi.common.domain.SendData;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -359,6 +360,29 @@ public class Tools implements Serializable {
|
|||||||
return df.format(t);
|
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字节
|
//int 转2字节
|
||||||
public static byte[] intbyte(int res) {///Java中10进制转byte[]
|
public static byte[] intbyte(int res) {///Java中10进制转byte[]
|
||||||
byte[] targets = new byte[2];
|
byte[] targets = new byte[2];
|
||||||
|
|||||||
Reference in New Issue
Block a user