|
|
|
|
@ -144,6 +144,7 @@ public class RFIDSocket {
|
|
|
|
|
//只能根据长度判断返回的包是标签内容还是其他
|
|
|
|
|
//9个字节,第一个字节是指哪个天线,暂时不用管,只需关注什么标签
|
|
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
|
System.out.println("antId:"+String.format("%02X",messageTran.getAryData()[0]));
|
|
|
|
|
for(int i = 1;i<messageTran.getAryData().length;i++){
|
|
|
|
|
sb.append(String.format("%02X",messageTran.getAryData()[i]));
|
|
|
|
|
}
|
|
|
|
|
@ -173,10 +174,43 @@ public class RFIDSocket {
|
|
|
|
|
Thread thread = new Thread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (true){
|
|
|
|
|
if(!running){
|
|
|
|
|
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];
|
|
|
|
|
bytes[0] = (byte)0xa0;
|
|
|
|
|
bytes[1] = (byte)0x03;
|
|
|
|
|
@ -197,7 +231,7 @@ public class RFIDSocket {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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.readData();
|
|
|
|
|
Thread.sleep(10000);
|
|
|
|
|
|