Main Site Documentation

Advise on coding RFID reader


#1

HI guys
Im working on my RFID reader.
Right now im using a SerialDataReceivedEventHandler
Foreach all the chars out, stoppen when i reach the end char…

But problem is that the reader will run the event handler alot of times.
And i only want it to read the tag ones, and then have some sort of disabled timer, where it wont read, so it doesnt read the tag multiple times.

Anyone who can help? maybe an example on how a good idea would be to build a class for this?


#2

What kind of reader is that?

You can unsubscribe from the event when you don’t need to receive it. Is that what you are looking for?


#3

With a serial port DataReceived event, you have no control about how many times the event handler will be called. You can not expect it to only be called once per RFID tag swipe.
You have to be prepared to receive multiple events, and you have to process the each event until you have assembled an entire RFID messages.


#4

Its this one: http://www.let-elektronik.dk/filer/produkter/tradlos_rfid_125_uart_module.pdf
Page 4…

This is what i have right now:

public static void RFID_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            Debug.Print("Tag Detected");
            
            char SerialStart = (char)2;
            char SerialEnd = (char)3;
            string SerialString = null;

            if (RFID.BytesToRead > 0) {
                Debug.Print("data recieved");
                byte[] ReadBuffer = new byte[RFID.BytesToRead];

                RFID.Read(ReadBuffer, 0, ReadBuffer.Length);
                char[] ReceivedChars = Encoding.UTF8.GetChars(ReadBuffer);
                foreach (char c in ReceivedChars) {
                    if (c != SerialEnd) {
                        SerialString = string.Concat(SerialString, c);
                    }
                    if (c == SerialEnd) {
                        string TagTmp = SerialString.Substring(2, 8);
                        int tagInt = Convert.ToInt32(TagTmp, 16);
                        Debug.Print(tagInt.ToString());
                    }
                }
            }
        }

But this will read the tag alot of times… i want it to read it once, and then maybe wait 5 sec, before it will be able to read a tag again.


#5

Since you have declared string SerialString as an automatic within the event handler, it will not assemble a complete message.

I suggest you use the debugger to see how the characters are arriving and how you processing is working.

It will take at least two events before you get an entire message.


#6

I assume tag has a fixed length? I would declare the buffer once, outside of the method, and will reuse it.

Also check Codeshare we have examples for several readers there:

http://www.tinyclr.com/codeshare/search?q=RFID

When it come to reading a tag they all pretty much the same.


#7

ohh yeah, i know, i just removed some of my testing stuff from the code, before i posted it, forgot to place that one in the right place.

But it reads just fine. only problem is that it does it multiple times…

So its really just how to make sure i only get the tags once, and then wait. for a new.

Cause im going to send the tag’s data over bluetooth, and i dont want it to be spamming out the tag again and again.

@ Architect
I tryed the seeduino driver, but it crashes for some reason when i read a tag, and quits debug aswell with no error…
Thats why i decided to build one myself…
The other ones seems a bit complicated


#8

if it’s reading it multiple times, the “problem” is with the reader not your software. You’re going to have to build app logic to control that yourself. When you hit an end-of-tag you could bubble up an event and only dispatch that over BT if your last send was different and the time was longer than 5 seconds ago.