|
Question : Using the SCardTransmit method
|
|
I have a reader, SCM Microsystems Inc. SCR331-DI USB ContactlessReader from SCM. I am attempting to read and write cards in C#.
I have done extensive research and i have been busy with this for a week. After reviewing many examples i am using the SCardTransmit method and I am finding it extremely difficult.
I send a write command and it returns with a 0, meaning it was successful. Then i send a read command and also get a return value of 0. So apparently the read was also successful, however we dont receive any data. We always get one byte that seems random.
Here is a example
int response = SCardEstablishContext(2, 0, 0, ref hSCardCtx);
After this we get the context.
response = SCardConnect(hSCardCtx, szReaderName, dwShareMode, dwPrefProtocol, ref hCard, ref ActiveProtocol);
After this we have a handle.
This is the command we send for reading from block 1.
byteCommand[0] = 0xFC; byteCommand[1] = 0xB0; byteCommand[2] = 0x01; byteCommand[3] = 0x00; byteCommand[4] = 0x00;
we have also tried to include the number of bytes we want to read(byteCommand[4] = 0x05), but it still did not work.
response = SCardTransmit(hCard, 0, byteCommand, dwSendLength, 0, ref pbRecvBuffer, ref dwRecvLength);
With all of these parameters we get a response of 0. The pbRecvBuffer array returns only 1 byte instead of all the data we supposedly wrote to the card.(the write method returned a 0 code as well)
Can anyone please give me a example of the entire process, from start to finish, for first writing and then reading to cards. I do not have any driver problems and the reader is working properly. All im looking for is 1) what parameters to parse the transmit method for both cases 2)a explanation as to why my code is returning 0s but we see no result.
thanks
|
|
Answer : Using the SCardTransmit method
|
|
My team and I have sorted this issue out.
It was challenging and I hope this solution helps others that have trouble using the SCardTransmit command.
The transmit command transmits commands to the smart card, then if the command is sent successfully, the response code is 0. This does NOT mean the card accepted the command. The receive buffer byte array returns two values, SW1 and SW2. When these are 90 and 00 respectivley, then the command was accepted.
Our trouble was finding out witch APDUs to use with our card and what data types to use in c#. Our handle had to be a intPtr and all other integers had to be UInts. Also make sure that the protocalls are bing sent as specified in MSDN.
Hope it helps
|
|
|
|