Search code examples
c#multithreadingrfid

Trying to read RFID reader's response after writing a command to it, but getting an empty response


RFID name: YHY502CTG 13.56MHz RFID Mifare Read/Write Module

I am trying to write this command "AA BB 02 20 22" to RFID, in response to which i'll get

1) if no card is swiped == "AA BB 02 DF DD" .
Where "AA BB" == Head of this DATA , 
02 == Length of this DATA,
"DF" == One's complement of COMMAND,
02⊕DF(XOR) == "DD"

2) if there is card swipe == "AA BB 06 20 A0 8C 92 54 CC" 
where "AA BB" == Head of this DATA , 
06 == Length of this DATA, 
20 == COMMAND, 
"A0 8C 92 54" == Card Serial Number,  
06⊕20⊕A0⊕8C⊕92⊕54(XOR) == "CC".

CODE:-
byte[] bytesToSend = new byte[10] { 0x41, 0x41, 0x42, 0x42, 0x30, 0x32, 0x32, 0x30, 0x32, 0x32 };
_comport.Write(bytesToSend,0,10);// dont know whether ----correct way to write , but working properly//
System.Threading.Thread.Sleep(1000);
var data1 = _comport.ReadExisting();//getting an empty response
MessageBox.Show(data1);

Solution

  • I have the same problem. I assume you communicate with your reader via the serial port?

    Try installing the free serial analyzer tool, with this tool you can see what data is send and what is received to exclude coding mistakes.

    Is there any Software shipped with the reader to get access to it? For me it helped first to connect and disconnect via the shipped software to my reader and after that I got responses from my reader when sending commands through my own code. Unfortunately I don't know why and I'm still looking for a better way.