增加天线切换

merge-requests/5/merge
yiming 4 years ago
parent 6472133931
commit 4a3dfd7009

@ -144,6 +144,7 @@ public class RFIDSocket {
//只能根据长度判断返回的包是标签内容还是其他 //只能根据长度判断返回的包是标签内容还是其他
//9个字节第一个字节是指哪个天线暂时不用管只需关注什么标签 //9个字节第一个字节是指哪个天线暂时不用管只需关注什么标签
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
System.out.println("antId:"+String.format("%02X",messageTran.getAryData()[0]));
for(int i = 1;i<messageTran.getAryData().length;i++){ for(int i = 1;i<messageTran.getAryData().length;i++){
sb.append(String.format("%02X",messageTran.getAryData()[i])); sb.append(String.format("%02X",messageTran.getAryData()[i]));
} }
@ -173,10 +174,43 @@ public class RFIDSocket {
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
int i = 0;
while (true){ while (true){
if(!running){ if(!running){
break; break;
} }
if(i % 2 == 0){
//切换天线 使用天线0
byte[]bytes = new byte[6];
bytes[0] = (byte)0xa0;
bytes[1] = (byte)0x04;
bytes[2] = (byte)0x22;
bytes[3] = (byte)0x74;
bytes[4] = (byte)0x00;
bytes[5] = (byte)0xc6;
try {
os.write(bytes);
Thread.sleep(70);
} catch (InterruptedException | IOException e) {
log.error("send cmd error:{}",e);
}
}else {
//切换天线 使用天线1
byte[]bytes = new byte[6];
bytes[0] = (byte)0xa0;
bytes[1] = (byte)0x04;
bytes[2] = (byte)0x22;
bytes[3] = (byte)0x74;
bytes[4] = (byte)0x01;
bytes[5] = (byte)0xc5;
try {
os.write(bytes);
Thread.sleep(70);
} catch (InterruptedException | IOException e) {
log.error("send cmd error:{}",e);
}
}
i++;
byte[]bytes = new byte[5]; byte[]bytes = new byte[5];
bytes[0] = (byte)0xa0; bytes[0] = (byte)0xa0;
bytes[1] = (byte)0x03; bytes[1] = (byte)0x03;
@ -197,7 +231,7 @@ public class RFIDSocket {
} }
public static void main(String[] args) throws IOException, InterruptedException { public static void main(String[] args) throws IOException, InterruptedException {
RFIDSocket rfid = new RFIDSocket("172.16.2.28",4001); RFIDSocket rfid = new RFIDSocket("172.16.0.220",4001);
rfid.startCheck(); rfid.startCheck();
rfid.readData(); rfid.readData();
Thread.sleep(10000); Thread.sleep(10000);

Loading…
Cancel
Save