|
|
|
@ -4,9 +4,11 @@ import com.payne.connect.net.NetworkHandle;
|
|
|
|
import com.payne.reader.Reader;
|
|
|
|
import com.payne.reader.Reader;
|
|
|
|
import com.payne.reader.base.Consumer;
|
|
|
|
import com.payne.reader.base.Consumer;
|
|
|
|
import com.payne.reader.bean.config.AntennaCount;
|
|
|
|
import com.payne.reader.bean.config.AntennaCount;
|
|
|
|
|
|
|
|
import com.payne.reader.bean.config.MemBank;
|
|
|
|
import com.payne.reader.bean.receive.*;
|
|
|
|
import com.payne.reader.bean.receive.*;
|
|
|
|
import com.payne.reader.bean.send.FastSwitchFourAntennaInventory;
|
|
|
|
import com.payne.reader.bean.send.FastSwitchFourAntennaInventory;
|
|
|
|
import com.payne.reader.bean.send.InventoryConfig;
|
|
|
|
import com.payne.reader.bean.send.InventoryConfig;
|
|
|
|
|
|
|
|
import com.payne.reader.bean.send.ReadConfig;
|
|
|
|
import com.payne.reader.process.ReaderImpl;
|
|
|
|
import com.payne.reader.process.ReaderImpl;
|
|
|
|
import com.payne.reader.util.ArrayUtils;
|
|
|
|
import com.payne.reader.util.ArrayUtils;
|
|
|
|
|
|
|
|
|
|
|
|
@ -26,15 +28,14 @@ public class RFIDSocket {
|
|
|
|
private Map<String, Integer> tagsCount = new ConcurrentHashMap<>();
|
|
|
|
private Map<String, Integer> tagsCount = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
String tagStr = "363000145224505289907900";
|
|
|
|
RFIDSocket rfidSocket = new RFIDSocket("192.168.2.66", 2001);
|
|
|
|
if(tagStr.startsWith("363000") &&tagStr.endsWith("00")){
|
|
|
|
rfidSocket.readTid();
|
|
|
|
tagStr = tagStr.substring(0, tagStr.length() - 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println(tagStr);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Set<String> getTags() {
|
|
|
|
public Set<String> getTags() {
|
|
|
|
return tags;
|
|
|
|
return tags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public RFIDSocket(String ip, Integer port) {
|
|
|
|
public RFIDSocket(String ip, Integer port) {
|
|
|
|
this.ip = ip;
|
|
|
|
this.ip = ip;
|
|
|
|
this.port = port;
|
|
|
|
this.port = port;
|
|
|
|
@ -42,11 +43,11 @@ public class RFIDSocket {
|
|
|
|
NetworkHandle handle = new NetworkHandle(ip, (port));
|
|
|
|
NetworkHandle handle = new NetworkHandle(ip, (port));
|
|
|
|
mReader = ReaderImpl.create(AntennaCount.FOUR_CHANNELS);
|
|
|
|
mReader = ReaderImpl.create(AntennaCount.FOUR_CHANNELS);
|
|
|
|
|
|
|
|
|
|
|
|
boolean linkSuccess =false;
|
|
|
|
boolean linkSuccess = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
linkSuccess = mReader.connect(handle);
|
|
|
|
linkSuccess = mReader.connect(handle);
|
|
|
|
|
|
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (linkSuccess) {
|
|
|
|
if (linkSuccess) {
|
|
|
|
@ -57,40 +58,71 @@ public class RFIDSocket {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void startCheck(Integer direction,boolean foreach) {
|
|
|
|
public Set<String> readTid() {
|
|
|
|
|
|
|
|
ReadConfig config = new ReadConfig.Builder().setMemBank(MemBank.TID).setWordLength((byte) 6).build();
|
|
|
|
|
|
|
|
Set<String> tags = new HashSet<>();
|
|
|
|
|
|
|
|
byte[] bytes = new byte[1];
|
|
|
|
|
|
|
|
bytes[0] = 0x01;
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
while (count<100) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
bytes[0] = (byte) (bytes[0] == 0x01 ? 0x00 : 0x01);
|
|
|
|
|
|
|
|
Thread.sleep(200);
|
|
|
|
|
|
|
|
mReader.setWorkAntenna(bytes[0], (v) -> {
|
|
|
|
|
|
|
|
System.out.println("reader1 setWorkAntenna success");
|
|
|
|
|
|
|
|
}, (v) -> {
|
|
|
|
|
|
|
|
System.out.println("reader1 setWorkAntenna fail");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
mReader.readTag(config
|
|
|
|
|
|
|
|
, (Consumer<OperationTag>) readTag -> {
|
|
|
|
|
|
|
|
System.out.println("readTag: " + readTag.toString());
|
|
|
|
|
|
|
|
tags.add(readTag.getStrData());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
, e -> System.out.println("readTag err: " + e.toString()));
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
stopCheck();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return tags;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void startCheck(Integer direction, boolean foreach) {
|
|
|
|
// Reader mReader = ReaderImpl.create(AntennaCount.SIXTEEN_CHANNELS);
|
|
|
|
// Reader mReader = ReaderImpl.create(AntennaCount.SIXTEEN_CHANNELS);
|
|
|
|
// Reader mReader = ReaderImpl.create(AntennaCount.EIGHT_CHANNELS);
|
|
|
|
// Reader mReader = ReaderImpl.create(AntennaCount.EIGHT_CHANNELS);
|
|
|
|
running = true;
|
|
|
|
running = true;
|
|
|
|
Thread thread = new Thread(new Runnable() {
|
|
|
|
Thread thread = new Thread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
|
|
|
|
mReader.setOriginalDataCallback(
|
|
|
|
mReader.setOriginalDataCallback(
|
|
|
|
new Consumer<byte[]>() {
|
|
|
|
new Consumer<byte[]>() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void accept(byte[] onSend) throws Exception {
|
|
|
|
public void accept(byte[] onSend) throws Exception {
|
|
|
|
//System.out.println("---reader 1 send :" + ArrayUtils.bytesToHexString(onSend, 0, onSend.length));
|
|
|
|
System.out.println("---reader 1 send :" + ArrayUtils.bytesToHexString(onSend, 0, onSend.length));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new Consumer<byte[]>() {
|
|
|
|
new Consumer<byte[]>() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void accept(byte[] onReceive) throws Exception {
|
|
|
|
public void accept(byte[] onReceive) throws Exception {
|
|
|
|
|
|
|
|
System.out.println("===reader 1 recv:" + ArrayUtils.bytesToHexString(onReceive, 0, onReceive.length));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
FastSwitchFourAntennaInventory inventory = new FastSwitchFourAntennaInventory.Builder().build();
|
|
|
|
FastSwitchFourAntennaInventory inventory = new FastSwitchFourAntennaInventory.Builder().build();
|
|
|
|
|
|
|
|
|
|
|
|
InventoryConfig config = new InventoryConfig.Builder()
|
|
|
|
InventoryConfig config = new InventoryConfig.Builder()
|
|
|
|
.setInventory(inventory)
|
|
|
|
.setInventory(inventory)
|
|
|
|
.setOnInventoryTagSuccess(new Consumer<InventoryTag>() {
|
|
|
|
.setOnInventoryTagSuccess(new Consumer<InventoryTag>() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void accept(InventoryTag tag) throws Exception {
|
|
|
|
public void accept(InventoryTag tag) throws Exception {
|
|
|
|
System.out.println("reader1 inventory tag :" + tag.getEpc());
|
|
|
|
System.out.println("reader1 inventory tag :" + tag.toString());
|
|
|
|
String tagStr = tag.getEpc().replace(" ","");
|
|
|
|
String tagStr = tag.getEpc().replace(" ", "");
|
|
|
|
System.out.println("tag: " + tag.getEpc());
|
|
|
|
System.out.println("tag: " + tag.getEpc());
|
|
|
|
// 去除头为0
|
|
|
|
// 去除头为0
|
|
|
|
tagStr = tagStr.replace("0000000000","");
|
|
|
|
tagStr = tagStr.replace("0000000000", "");
|
|
|
|
//去除尾巴为0
|
|
|
|
//去除尾巴为0
|
|
|
|
if(tagStr.startsWith("363000") &&tagStr.endsWith("00")){
|
|
|
|
if (tagStr.startsWith("363000") && tagStr.endsWith("00")) {
|
|
|
|
tagStr = tagStr.substring(0, tagStr.length() - 2);
|
|
|
|
tagStr = tagStr.substring(0, tagStr.length() - 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tags.add(tagStr);
|
|
|
|
tags.add(tagStr);
|
|
|
|
@ -105,6 +137,7 @@ public class RFIDSocket {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void accept(InventoryTagEnd arg0) throws Exception {
|
|
|
|
public void accept(InventoryTagEnd arg0) throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
// System.out.println("reader1 InventoryTagEnd");
|
|
|
|
// System.out.println("reader1 InventoryTagEnd");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
@ -138,11 +171,11 @@ public class RFIDSocket {
|
|
|
|
while (running) {
|
|
|
|
while (running) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
bytes[0] = (byte) (bytes[0] == 0x01 ? 0x00 : 0x01);
|
|
|
|
bytes[0] = (byte) (bytes[0] == 0x01 ? 0x00 : 0x01);
|
|
|
|
Thread.sleep(1000);
|
|
|
|
Thread.sleep(200);
|
|
|
|
if(foreach){
|
|
|
|
if (foreach) {
|
|
|
|
mReader.setWorkAntenna(bytes[0],(v)->{
|
|
|
|
mReader.setWorkAntenna(bytes[0], (v) -> {
|
|
|
|
System.out.println("reader1 setWorkAntenna success");
|
|
|
|
System.out.println("reader1 setWorkAntenna success");
|
|
|
|
},(v)->{
|
|
|
|
}, (v) -> {
|
|
|
|
System.out.println("reader1 setWorkAntenna fail");
|
|
|
|
System.out.println("reader1 setWorkAntenna fail");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|