如何通过LLRP从EPC RFID标签读取用户数据(内存)?

时间:2018-09-18 09:15:12

标签: java memory format rfid llrp

我通过“ NiceLabel Pro”使用数据对两个EPC标签进行了编码:

  1. 第一个标签:EPC:555555555,UserData:9876543210123456789
  2. 第二个标签:EPC:444444444,UserData:123456789123456789

现在,我正尝试通过LLRP(在我的Java应用程序中)获取数据:

我的LLRPClient(一个功能):

public void PrepareInventoryRequest() {
    AccessCommand accessCommand = new AccessCommand();

    // A list to hold the op specs for this access command.
    accessCommand.setAccessCommandOpSpecList(GenerateOpSpecList());

    // Create a new tag spec.
    C1G2TagSpec tagSpec = new C1G2TagSpec();
    C1G2TargetTag targetTag = new C1G2TargetTag();
    targetTag.setMatch(new Bit(1));
    // We want to check memory bank 1 (the EPC memory bank).
    TwoBitField memBank = new TwoBitField("2");
    targetTag.setMB(memBank);
    // The EPC data starts at offset 0x20.
    // Start reading or writing from there.
    targetTag.setPointer(new UnsignedShort(0));
    // This is the mask we'll use to compare the EPC.
    // We want to match all bits of the EPC, so all mask bits are set.
    BitArray_HEX tagMask = new BitArray_HEX("00");
    targetTag.setTagMask(tagMask);
    // We only only to operate on tags with this EPC.
    BitArray_HEX tagData = new BitArray_HEX("00");
    targetTag.setTagData(tagData);

    // Add a list of target tags to the tag spec.
    List <C1G2TargetTag> targetTagList =
            new ArrayList<>();
    targetTagList.add(targetTag);
    tagSpec.setC1G2TargetTagList(targetTagList);

    // Add the tag spec to the access command.
    accessCommand.setAirProtocolTagSpec(tagSpec);

    accessSpec.setAccessCommand(accessCommand);
...

private List<AccessCommandOpSpec> GenerateOpSpecList() {
    // A list to hold the op specs for this access command.
    List <AccessCommandOpSpec> opSpecList =
            new ArrayList<>();

    // Set default opspec which for eventcycle of accessspec 3.
    C1G2Read opSpec1 = new C1G2Read();
    // Set the OpSpecID to a unique number.
    opSpec1.setOpSpecID(new UnsignedShort(1));
    opSpec1.setAccessPassword(new UnsignedInteger(0));

    // We'll read from user memory (bank 3).
    TwoBitField opMemBank = new TwoBitField("3");
    opSpec1.setMB(opMemBank);

    // We'll read from the base of this memory bank (0x00).
    opSpec1.setWordPointer(new UnsignedShort(0));
    // Read two words.
    opSpec1.setWordCount(new UnsignedShort(0));

    opSpecList.add(opSpec1);

    return opSpecList;
}

我的代码处理函数:

 private void updateTable(TagReportData tag) {
    if (tag != null) {
        EPCParameter epcParam = tag.getEPCParameter();
        String EPCStr;

        List<AccessCommandOpSpecResult> accessResultList = tag.getAccessCommandOpSpecResultList();

        for (AccessCommandOpSpecResult accessResult : accessResultList) {
            if (accessResult instanceof C1G2ReadOpSpecResult) {
                C1G2ReadOpSpecResult op = (C1G2ReadOpSpecResult) accessResult;
                if ((op.getResult().intValue() == C1G2ReadResultType.Success) &&
                        (op.getOpSpecID().intValue() < 1000)) {
                    UnsignedShortArray_HEX userMemoryHex = op.getReadData();
                    System.out.println("User Memory read from the tag is = " + userMemoryHex.toString());
                }
            }
        }
...

对于第一个标签,“ userMemoryHex.toString()” =“ 3938 3736”
对于第二个标签,“ userMemoryHex.toString()” =“ 3132 3334”

为什么?如何获取所有用户数据?

这是my rfid tag

1 个答案:

答案 0 :(得分:2)

您获得的值似乎是数字的前4个字符(解释为ASCII字符串):

  • 39383736 =“ 9876”(当将这4个字节解释为ASCII字符时)
  • 31323334 =“ 1234”(将这4个字节解释为ASCII字符时)

由于标签的specification表示

  

内存:EPC 128位,用户 32位

您的标签只能包含32位(= 4字节)的用户数据。因此,您的标记根本就不能包含您尝试写入为UserData的完整值(即9876543210123456789或123456789123456789)(无论该值是解释为十进制数字还是字符串)。

相反,您的编写器应用程序似乎已采用了这些值的前4个字符,并以ASCII编码,并将其写入了标签。