首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何通过LLRP从EPC标签读取用户数据(内存)?

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

Stack Overflow用户
提问于 2018-09-18 09:15:12
回答 1查看 1.1K关注 0票数 2

我用数据通过"NiceLabel Pro“编码了两个EPC标记:

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

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

我的LLRPClient (一个函数):

代码语言:javascript
运行
复制
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;
}

我的标记处理函数:

代码语言:javascript
运行
复制
 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()“=”39383736“

对于第二个标记,"userMemoryHex.toString()“= "3132 3334”

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

我是我的rfid标签

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-18 16:45:09

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

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

因为标签的规格说明

内存: EPC 128位,用户32位

标记只能包含32位(= 4字节)的用户数据。因此,您的标记不能包含您试图将其写入为UserData的全部值(即9876543210123456789或123456789123456789) (不管它是被解释为十进制数字还是字符串)。

相反,您的作者应用程序似乎接受了这些值的前4个字符,用ASCII对它们进行编码,并将它们写入标记。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52383074

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档