NfcV Transceive command throws tag lost exception with TI HF-I plus tag(ISO15693) in android

浪子不回头ぞ 提交于 2019-12-12 09:04:29

问题


I am trying to talk to a ISO15693 Tag. Tag type is TI HF-I Plus. When I issue a Get System Info command, the command executes normally and a proper response is received. For most other commands sent to the tag, the framework does not seem to handle the response properly. TAG LOST exception is thrown for most other commands. Has anyone successfully implemented ISO15693 commands in Android ?

Source code:

@Override
protected byte[] doInBackground(byte[]... params) {

    NfcV mNfcVObject = NfcV.get(mTag);
    byte[] mCommand = null;

    switch(params[0][0]){
        case ReadSingleBlock:
            mCommand = new byte[]{0x02, 0x20, params[1][0]};
            break;
        case ReadMultipleBlocks:
            mCommand = new byte[]{0x02, 0x23,params[1][0],params[2][0]};
            break;
        case WriteSingleBlock:
            mCommand = new byte[]{0x42, 0x21, (byte)params[1][0],params[2][0],params[2][1],params[2][2],params[2][3]};
            break;
        case GetSystemInfo:
            mCommand = new byte[]{0x00,(byte)0x2B};
            break;
    }


    if (mNfcVObject != null) {
        try {
            mNfcVObject.connect();
        } catch (IOException e) {
            e.printStackTrace();
            Log.e(LOG_TAG, e.toString());
        }

        if (mNfcVObject.isConnected()) {

            int i = 0;

                try {
                    mResponse = mNfcVObject.transceive(mCommand);
                    String responseString = FlomioNdefHelper.mBytesToHexString(mResponse);
                    Log.d(String.format(LOG_TAG + " Response %d", i), responseString);
                } catch (IOException e) {
                    e.printStackTrace();
                    Log.e(LOG_TAG, e.toString());
                }

            try {
                mNfcVObject.close();
            } catch (IOException e) {
                e.printStackTrace();
                Log.e(LOG_TAG, e.toString());
            }
        }
    }

    return mResponse;
}

@Override
protected void onPostExecute(byte[] response) {
    super.onPostExecute(response);
    mOnCommandExecutedCallBack.onCommandExecuted(response);
    return;
}

来源:https://stackoverflow.com/questions/16903536/nfcv-transceive-command-throws-tag-lost-exception-with-ti-hf-i-plus-tagiso15693

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!