|
@@ -5,6 +5,7 @@ import android.util.Log;
|
|
import com.wdkl.ncs.android.middleware.common.Constant;
|
|
import com.wdkl.ncs.android.middleware.common.Constant;
|
|
|
|
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteBuffer;
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
import serialporttest.utils.SerialPortUtil;
|
|
import serialporttest.utils.SerialPortUtil;
|
|
|
|
|
|
@@ -165,6 +166,43 @@ public class SerialPortHelper {
|
|
SerialPortUtil.getInstance().send(bytes);
|
|
SerialPortUtil.getInstance().send(bytes);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static void s485PowerControlLines(Integer controlAddress, List<String> lineNumbers, Boolean off){
|
|
|
|
+ if(lineNumbers.size() < 1){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ String address = String.format("%02x",controlAddress&0xFF);
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
+ sb.append("24").append(address).append("2C");
|
|
|
|
+
|
|
|
|
+ String controlStatus = "FFFFFFFF"; //默认所有电路开启
|
|
|
|
+ byte[] commandBytes = hexStringToByteArray(controlStatus);
|
|
|
|
+ if (off) {
|
|
|
|
+ for (String num : lineNumbers) {
|
|
|
|
+ int line = Integer.parseInt(num);
|
|
|
|
+ if (line < 0 || line > 32) { //传入线路序号小于0或者大于28,认为无效线路,如果是0认为是控制所有线路
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (line > 0) {
|
|
|
|
+ controlStatus = POWER_CONTROL_STATUS[line - 1];
|
|
|
|
+ byte[] temp = hexStringToByteArray(controlStatus);
|
|
|
|
+ //多路控制,按位取&
|
|
|
|
+ for (int i = 0; i < commandBytes.length; i++) {
|
|
|
|
+ commandBytes[i] = (byte) (temp[i] & commandBytes[i]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < commandBytes.length; i++) { //与协议相反,按位取反
|
|
|
|
+ commandBytes[i]=(byte)~commandBytes[i];
|
|
|
|
+ }
|
|
|
|
+ sb.append(byteArrToHexString(commandBytes)).append("4623");
|
|
|
|
+ byte[] bytes=hexStringToByteArray(sb.toString());
|
|
|
|
+ Log.i("s485PowerControl", "s485PowerControl: "+bytes[0]+","+bytes[1]+","+bytes[2]+","+bytes[3]+","+bytes[4]+","+bytes[5]+","+bytes[6]+","+bytes[7]+","+bytes[8]+",");
|
|
|
|
+ SerialPortUtil.getInstance().send(bytes);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
public static byte[] intToBytes(int a){
|
|
public static byte[] intToBytes(int a){
|
|
ByteBuffer bb = ByteBuffer.allocate(4);
|
|
ByteBuffer bb = ByteBuffer.allocate(4);
|