我正在尝试与 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;
}