0

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);
  • You might not be waiting long enough for a response. You can subscribe to the `SerialPort.DataReceived` event to make sure that you are getting data and waiting long enough for a response. – KDecker Oct 21 '15 at 14:21
  • Hi @KDecker, I tried writing System.Threading.Thread.Sleep(5000); before reading using ReadExisting() , also i tried var data1 = ""; while (data1.Length < 4) { data1 = _comport.ReadExisting(); } ---// but it goes into infinite loop , because the response is empty. – Tapan Tripathi Oct 23 '15 at 06:17
  • You need to hook into the `DataReceived` event itself and write an appropriate handler. Something like `RFIDDataReceivded += MySerialPortObj.DataReceived`. Then implement `RFIDDataReceived` and read the existing bytes/string in the buffer. // If this handler is not called you most likely have an issue with your connection to the device. – KDecker Oct 23 '15 at 17:39

1 Answers1

0

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.

croxy
  • 4,082
  • 9
  • 28
  • 46
  • Hello @croxy , I'm using Docklight V2.1 to see what data is send and received, the application is working properly with it.And also i didn't got any software with the reader. – Tapan Tripathi Oct 23 '15 at 06:03
  • Thank You @croxy, It helped, the free serial analyzer tool, was actually showing the data what i was trying to send . Previously i was using Docklight V2.1 to see what is actually going to port , it was also working but the way this particular RFID wants the data was actually shown by the free serial analyzer tool. Thanks Again.. :) – Tapan Tripathi Nov 03 '15 at 06:20
  • @TapanTripathi Nice that I could help :) – croxy Nov 03 '15 at 07:20