I am trying to implement code that will perform an SCardReconnect for certain error conditions when trying to read a TI Tag-IT RFID card with an HID 5321 smart card reader. In the event of a transmit error, I try a reconnect and retry the operation. However, when I perform the reconnect, I get a return value of 6 (INVALID HANDLE). Here is the code for the call for a working SCardConnect, and the non working SCardReconnect.
int iRetval = HID.SCardConnect(
m_hContext,
m_sReaderName,
HiDWinscard.SCARD_SHARE_SHARED,
HiDWinscard.SCARD_PROTOCOL_T1,
ref m_hCard,
ref m_protocol);
int iRetval = HID.SCardReconnect(ref m_hCard,
HiDWinscard.SCARD_SHARE_SHARED,
HiDWinscard.SCARD_PROTOCOL_T1,
0, //Leave card alone SCARD_LEAVE_CARD
ref m_protocol);
Where m_hCard and m_protocol are the same (IntPtr).
The following SCardTransmit works as well, and it uses the same reference to m_hCard
iRetval = HID.SCardTransmit(m_hCard, ref sioreq,
sendBuffer, sendbufferlen,
ref rioreq, receiveBuffer,
ref receivebufferlen);
This is quite a pressing matter. Does anyone happen to have an idea of what may be going on? I thank everyone in advance for their help!
On a first quess, I would assume that you should not pass m_hCard as reference. Also I would reconnect using the protocol received from the initial connect as prefered protocol: