package baowen; import gnu.io.SerialPort; import index.JPanelMoudle.showDataComp; import tools.ChuanKou.SerialPortUtil; import tools.Jiaoyan; import tools.Tools; public class WriteReadAnchor { //给扫描器发送指令 public static void updateLora(String zhi, byte diZhi, byte duxie, String anchorID, SerialPort serialPort, byte lenth) { byte[] write = write_loraAnc(diZhi,lenth ,duxie, Integer.parseInt(zhi),anchorID); if (write == null) { return; } sendData(serialPort, write); } public static void sendData(SerialPort serialPort, byte[] write) { SerialPortUtil.sendData(serialPort,write); showDataComp.addSendAreaTextMes(write); } /**@param start 起始地址 * @param lenth数据长度 * @param value[]具体的值*/ private static byte[] write_loraAnc(byte start ,byte lenth,byte duXie,int value,String id) { byte[] buf =new byte[12+lenth]; byte[] buf1 =new byte[8+lenth]; //包头 buf[0]=(byte) 0x55; //包头 buf[1]=(byte) 0xAA; //指令类型 buf1[0]=(byte) 0x30; //数据长度 buf1[1]=(byte) ((byte) 8+lenth); //读模式 buf1[2]=(byte) duXie; //起始地址 buf1[3]=(byte) start; buf1[4]= Tools.toByteArray(id)[1]; buf1[5]=Tools.toByteArray(id)[0]; buf1[6]=Tools.toByteArray(id)[1]; buf1[7]=Tools.toByteArray(id)[0]; buf1[8]=Tools.intToRegisters(value)[3]; buf1[9]=Tools.intToRegisters(value)[2]; for(int i=0;i