Hallo Zusammen,
ich bin Peter und erst seit ganz kurzem mit Tinkerforge unterwegs.
Ich spiele gerade mit RFID herum. Leider habe ich ein kleines Problem.
Entwickelt wird in c#. Eingebunden ist das ganze in einer Testumgebung bestehend aus einem Form mit diversen Schaltflächen. Firmware (RFID Bricklet) 2.0.1. Über eine Schaltfläche wird RequestTagID() angestoßen bzw. registriert.
Drücke ich die Schaltfläche das erste mal, dann wir im Ausgabefenster richtig "15:52:25 - Status-STATE_REQUEST_TAG_ID: 2" angezeigt. Die Funktion wurde also richtig registriert. Allerdings wird ein Tag beim Auflegen nicht erkannt (oder nur jedes 20.-50. Mal).
Wenn ich jetzt die Schaltfläche ein zweites Mal betätige, dann wird der Tag jedesmal erkannt.
Ich kann mir das Verhalten gerade nicht erklären und konnte auch im Forum nichts dazu finden. Einer von Euch eine Idee?
Vielen Dank und liebe Grüße,
Peter
private void button9_Click(object sender, EventArgs e)
{
string UID = "p6p"; // Change to your UID
byte currentTagType = BrickletNFCRFID.TAG_TYPE_MIFARE_CLASSIC;
IPConnection ipcon = new IPConnection(); // Create IP connection
BrickletNFCRFID nfc = new BrickletNFCRFID(UID, ipcon); // Create device object
ipcon.Connect(HOST, PORT); // Connect to brickd
// Don't use device before ipcon is connected
// Register state changed callback to function StateChangedCB
nfc.StateChanged += StateChangedCB;
nfc.RequestTagID(BrickletNFCRFID.TAG_TYPE_MIFARE_CLASSIC);
updateLog("RFID gestartet");
//ipcon.Disconnect();
}
// Callback function for state changed callback
static void StateChangedCB(BrickletNFCRFID sender, byte state, bool idle)
{
//Console.WriteLine(System.DateTime.Now.ToString("HH:mm:ss") + " - Status: " + state.ToString());
if (idle)
{
//Console.WriteLine(System.DateTime.Now.ToString("HH:mm:ss") + " - Status-Idle: " + state.ToString());
currentTagType = (byte)((currentTagType + 1) % 3);
sender.RequestTagID(currentTagType);
}
if (state == BrickletNFCRFID.STATE_REQUEST_TAG_ID)
{
Console.WriteLine(System.DateTime.Now.ToString("HH:mm:ss") + " - Status-STATE_REQUEST_TAG_ID: " + state.ToString());
}
if (state == BrickletNFCRFID.STATE_REQUEST_TAG_ID_READY)
{
Console.WriteLine(System.DateTime.Now.ToString("HH:mm:ss") + " - Status-STATE_REQUEST_TAG_ID_READY: " + state.ToString());
Console.Beep(1000, 300);
byte tagType;
byte tidLength;
byte[] tid;
sender.GetTagID(out tagType, out tidLength, out tid);
int serial_int = 0;
string serial_hex = "";
if (tidLength == 7)
{
System.Console.WriteLine("Found tag of type {0} with ID " +
"[{1:X} {2:X} {3:X} {4:X} {5:X} {6:X} {7:X}]",
tagType, tid[0], tid[1], tid[2], tid[3], tid[4], tid[5], tid[6]);
serial_hex = tid[0].ToString("X") + tid[1].ToString("X") + tid[2].ToString("X") + tid[3].ToString("X") + tid[4].ToString("X") + tid[5].ToString("X") + tid[6].ToString("X");
}
else
{
System.Console.WriteLine("Found tag of type {0} with ID [{1:X} {2:X} {3:X} {4:X}]",
tagType, tid[0], tid[1], tid[2], tid[3]);
serial_hex = tid[0].ToString("X") + tid[1].ToString("X") + tid[2].ToString("X") + tid[3].ToString("X");
}
serial_int = Convert.ToInt32(serial_hex, 16);
Console.WriteLine(serial_int.ToString());
}
}