NfcV Transceive命令在Android中使用TI HF-I plus标签(ISO15693)引发标签丢失异常

时间:2013-06-03 18:37:51

标签: android exception nfc rfid iso-15693

我正在尝试与ISO15693标签对话。标签类型为TI HF-I Plus。当我发出Get System Info命令时,该命令正常执行并收到适当的响应。对于发送到标记的大多数其他命令,框架似乎没有正确处理响应。对于大多数其他命令,抛出TAG LOST异常。有没有人在Android中成功实现过ISO15693命令?

源代码:

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

0 个答案:

没有答案