2013-05-21 80 views
0

我正在使用ACS閱讀器和NFC標籤進行c#PC/SC實現。SCardTrasmit返回空接收字節數組

我都在原型的SCardTransmit如下:

​​

而且我有以下代碼:

 SCard.SCARD_IO_REQUEST ioRequest = new SCard.SCARD_IO_REQUEST(); 
     ioRequest.dwProtocol = Protocol; // Is going to be T=1 
     ioRequest.cbPciLength = 8; 

     byte[] cmdBytes = new byte[] { 0xFF, 0xCA, 0x00, 0x00, 0x00 }; 
     byte[] rcvBytes = new byte[10]; 
     int rcvLenght = 0; 

     retCode = SCard.SCardTransmit(Handle, 
      ref ioRequest, cmdBytes, cmdBytes.Length, 
      ref ioRequest, rcvBytes, out rcvLenght); 

     if (retCode != SCard.SCARD_S_SUCCESS) 
      throw new Exception("Failed querying tag UID: " + retCode); 

所有的(未顯示)init'ing東西似乎工作正常,我可以成功獲取標籤的ATR。

現在,運行此代碼我得到一個成功的返回碼,我收到一致的接收字節長度值,但對應的字節數組爲空(零)。

任何人都可以對此提出建議?

謝謝。

回答

1

SCardTransmit的原型很可能是這個問題。

[DllImport("winscard.dll")] 
public static extern uint SCardTransmit(Int32 hCard, SCARD_IO_REQUEST pioSendPci, [In] byte[] pbSendBuffer, uint cbSendLength, SCARD_IO_REQUEST pioRecvPci, [In, Out] byte[] pbRecvBuffer, ref uint pcbRecvLength); 

的主要區別是倒數第二個參數pbRecvBuffer,該聲明與屬性InOut:我會寫它。