I use mfrc522 library for raspberry pi 3 B+ and I have a problem with readblock method.
When I use ReadBlock()
method, no data of block is returned.
When I use Select()
method before calling ReadBlock()
method, it's done and returned data of block, but after that, any card or tag is not read.
Please help me that how to use read block and write block via this library.
Thanks a lot
This is my code:
var mfrc = new Mfrc522();
// mfrc.Reset();
await mfrc.InitIO();
while (true)
{
if (mfrc.IsTagPresent())
{
var uid = mfrc.ReadUid();
byte[] keyA = StringToByteArray("FFFFFFFFFFFF");
byte[] key1 = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
int intValue = 4;
byte[] intBytes = BitConverter.GetBytes(intValue);
if (BitConverter.IsLittleEndian)
Array.Reverse(intBytes);
byte[] result21 = intBytes;
mfrc.MifareAuthenticate(PiccCommands.AuthenticateKeyA, 3, uid, keyA);
byte[] result = mfrc.ReadBlock(31);
// bool bln = mfrc.SelectTag(uid);
//byte[] result = mfrc.ReadBlock(3, uid, keyA, keyA);
// mfrc.HaltSelect();
string txt_Result = "";
foreach (byte byt in result )//uid.FullUid)
{
txt_Result = txt_Result + byt.ToString("x2");
}
txtUID.Text = txt_Result;
mfrc.HaltTag();
// mfrc.MyReset();
//await mfrc.InitIO1();
}
}