javamemoryformatrfidllrp

How can I read user data (memory) from EPC RFID tag through LLRP?


I encode two EPC tags through "NiceLabel Pro" with data:

  1. First tag: EPC: 555555555, UserData: 9876543210123456789
  2. Second tag: EPC: 444444444, UserData: 123456789123456789

Now I'm trying to get that data through LLRP (in my Java application):

My LLRPClient (one function):

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;
}

My tag handler function:

 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());
                }
            }
        }
...

For the first tag, "userMemoryHex.toString()" = "3938 3736"
For the second tag, "userMemoryHex.toString()" = "3132 3334"

Why? How do I get all user data?

This is my rfid tag.


Solution

  • The values that you get seem to be the first 4 characters of the number (interpreted as an ASCII string):

    Since the specification of your tag says

    Memory: EPC 128 bits, User 32 bits

    your tag can only contain 32 bits (= 4 bytes) of user data. Hence, your tag simply can't contain the full value (i.e. 9876543210123456789 or 123456789123456789) that you tried to write as UserData (regardless of whether this was interpreted as a decimal number or a string).

    Instead, your writer application seems to have taken the first 4 characters of those values, encoded them in ASCII, and wrote them to the tag.