I have reader which has doc almost exact as this one: http://www.jinmuyu.com/download/JMY680A_EN.pdf main difference being, my reader claims it supports also TYPE B cards.
I have three ISO 14443 cards, which I test consecutively, and following code:
byte[] rs = null;
Thread.Sleep(500);
// Set module Idle
Random r = new Random();
byte rInt = (byte) r.Next(0, 255);
rs = send(new byte[] { 0x12, rInt });
if (rs[1] == 0xED)
throw new Exception("Failed set idle");
Thread.Sleep(500);
//// Request B
//rs = send(new byte[] { 0x60, 0x00, 0x00 });
//if (rs[1] == 0x9F)
// throw new Exception("Failed card requestB");
// RequestA
rs = send(new byte[] { 0x20, 0x00 });
if (rs[1] == 0xDF)
throw new Exception("Failed card requestA");
// Reset cardA
rs = send(new byte[] { 0x30 });
if(rs[1] == 0xCF)
throw new Exception("Failed card reset");
// Do other work, Send some APDU to card, etc.
// ........
// Exit program
Most of the time, this code works well with all three cards.
However, sometimes, when I bring one of the card near reader, the Card Request A (RequestA
call)
call fails. It will then always fail with this card, until I bring a new card to the reader.
Does anyone have any idea what can be causing this? Maybe I need some delays between calls? Or need to call some other (ISO14443 related) function before calling RequestA
?
send
is method implemented using SerialPort
class. In the following way:
SerialPort
object is createdOpen
on object created aboveWrite
and Read
some dataClose
on object which was created in this method instancebtw. this is successful response from one of the cards (on which reader failed once) on RequestA command:
ID | ATQ | SAK
0xe1 0x8f 0x68 0xe6 0x04 0x00 0x28
I can't be sure what the issue is from your code, but it seems to be a problem when a connection gets a error there is no new connection opened. Because a SerialPort is an hardware resource you will need to handle the dispose, the SerialPort probably implements IDisposable, which means you can use using be sure the connection is closed and disposed. Bring a new card will probably do this, however when you use the same card, you still working with the serial port in a fault state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With