如何只读取一个rfid标签

ubbxdtey  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(373)

我正在开发一个只需要读取一个rfid标签的应用程序,我尝试只读取第一个rfid标签,但问题是数组的零元素在不断变化,我可以在日志中看到它。
这是我的密码:
'''

// Read/Status Notify handler
// Implement the RfidEventsLister class to receive event notifications
public class EventHandler implements RfidEventsListener {
    // Read Event Notification
    public void eventReadNotify(RfidReadEvents e) {
        // Recommended to use new method getReadTagsEx for better performance in case of large tag population
        TagData[] myTags = reader.Actions.getReadTags(100);

        firstSeenTag = myTags[0].getTagID();
        Log.d(TAG, "firstSeenTag Tag ID " + firstSeenTag);

        if (myTags != null) {
            for (int index = 0; index < myTags.length; index++) {
                Log.d(TAG, "Tag ID " + myTags[index].getTagID());
                if (myTags[index].getOpCode() == ACCESS_OPERATION_CODE.ACCESS_OPERATION_READ &&
                        myTags[index].getOpStatus() == ACCESS_OPERATION_STATUS.ACCESS_SUCCESS) {
                    if (myTags[index].getMemoryBankData().length() > 0) {
                        Log.d(TAG, " Mem Bank Data " + myTags[index].getMemoryBankData());
                    }
                }
                if (myTags[index].isContainsLocationInfo()) {
                    short dist = myTags[index].LocationInfo.getRelativeDistance();
                    Log.d(TAG, "Tag relative distance " + dist);
                }
            }
            // possibly if operation was invoked from async task and still busy
            // handle tag data responses on parallel thread thus THREAD_POOL_EXECUTOR
            new AsyncDataUpdate().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, myTags);
        }
    }

    // Status Event Notification
    public void eventStatusNotify(RfidStatusEvents rfidStatusEvents) {
        Log.d(TAG, "Status Notification: " + rfidStatusEvents.StatusEventData.getStatusEventType());
        if (rfidStatusEvents.StatusEventData.getStatusEventType() == STATUS_EVENT_TYPE.HANDHELD_TRIGGER_EVENT) {
            if (rfidStatusEvents.StatusEventData.HandheldTriggerEventData.getHandheldEvent() == HANDHELD_TRIGGER_EVENT_TYPE.HANDHELD_TRIGGER_PRESSED) {
                new AsyncTask<Void, Void, Void>() {
                    @Override
                    protected Void doInBackground(Void... voids) {
                        context.handleTriggerPress(true);
                        Log.d(TAG, "firstSeenTag TriggerPress Tag ID " + firstSeenTag);
                        return null;
                    }
                }.execute();
            }
            if (rfidStatusEvents.StatusEventData.HandheldTriggerEventData.getHandheldEvent() == HANDHELD_TRIGGER_EVENT_TYPE.HANDHELD_TRIGGER_RELEASED) {
                new AsyncTask<Void, Void, Void>() {
                    @Override
                    protected Void doInBackground(Void... voids) {
                        context.handleTriggerPress(false);
                        Log.d(TAG, "firstSeenTag TriggerRelease Tag ID " + firstSeenTag);
                        return null;
                    }
                }.execute();
            }
        }
    }
}

'''
我尝试将number of labels参数更改为1,但没有效果。
''tagdata[]mytags=reader.actions.getreadtags(100);

firstSeenTag = myTags[0].getTagID();
        Log.d(TAG, "firstSeenTag Tag ID " + firstSeenTag);

'''
如您所见,我将数组的零值赋给firstseentag变量,但是根据日志判断,这个值被赋给每个读取的标记。

当然,您可以在读卡器上释放触发器时为变量赋值,但这对用户来说很不方便,因为只有释放读卡器的触发器才能看到读取rfid标签
读取一个rfid标签后如何停止读取?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题