我有一個問題讓我困惑了幾天。 我想發送一個大於255字節的數據從智能卡發送到主機應用程序。 我在一些網站上看到了一段代碼。此代碼如下:ISO7816.SW_BYTES_REMAINING_00在javacard中返回9000狀態
private void sendData(APDU apdu) {
// work out how many bytes to send this time and how many will be left
BUF_IN_OFFSET[0] = 0;
short remain = (short) ((short)372 - BUF_IN_OFFSET[0]);
boolean chain = remain > MAX_APDU;
short sendLen = chain ? MAX_APDU : remain;
Util.arrayCopy(data, (short) 0, apdu.getBuffer(), (short) 0, sendLen);
// Get ready to send
apdu.setOutgoing();
apdu.setOutgoingLength((short)sendLen);
apdu.sendBytesLong(apdu.getBuffer(), BUF_IN_OFFSET[0], sendLen);
// Check to see if there are more APDU's to send
if (chain) {
BUF_IN_OFFSET[0] += sendLen; // count the bytes sent
remain -=sendLen;
ISOException.throwIt((short)((ISO7816.SW_BYTES_REMAINING_00) + remain));
} else {
BUF_IN_OFFSET[0] = 0; // no more bytes to send
}
}
當我發送apdu到netbeans模擬器中的卡,它發送6100正確。但是當我把它發送到真正的卡(smartcafe 3.2)卡。它發送給我9000.這意味着它在模擬器的工作,但通過真正的卡它不工作。 我想它與協議T = 0或T = 1有關。 我沒有找到T = 1的任何代碼。上面的代碼是T = 0。
在此先感謝。
讓主應用程序保持關於偏移量的狀態不是更容易嗎? (即,提供'GET LENGTH'指令和一個帶有偏移參數的'READ BINARY'指令。) – martijno
在某些情況下,您的評論是真實的,例如,當您需要字節流時。但是在某些情況下,小程序會完成所有操作,例如讀取卡上生成的對象。 –