I've ordered more ID-20s recently and it seems the new batch (with "LV" prefix) from sparkfun exhibits weird issues. You can read some of them in the ID-20 thread. I've found that if you connect the reader to the 3v3 instead of 5v, it's almost 'normal'. I just dont know if this is a good idea moving forward or how consistent it'll be. I also saw another method using a resistor.
- Netduino Forums
- → Viewing Profile: Posts: buzz
Community Stats
- Group Members
- Active Posts 2
- Profile Views 4476
- Member Title New Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Not Telling
User Tools
Friends
buzz hasn't added any friends yet.
Posts I've Made
In Topic: ID-12/ID-20 RFID Reader Driver
07 February 2013 - 05:01 PM
In Topic: ID-12/ID-20 RFID Reader Driver
18 January 2013 - 06:32 AM
Finally got my ID-20 working well. A big THANK YOU to everyone here who contributed...this stuff is truly fascinating.
I plan to run this RFID scanner in production with ~50 employees on it. So after much stress testing, I'd like to contribute a few changes to the datareceived method to ensure maximum reliability. Particularly with ID-20 reading multiple cards in quick succession. Basically the code can't crash since no one may be around reboot it.
Changes I made:
- hopefully almost crashproof
- moved rawdata to local scope
- removed args.ReadTime, args.RFID output is now int, renamed class
- better error state output using args.Success (ie: to display error led's to user)
- better handles multiple/quick reads...basically when BytesToRead is not a perfect 16
- found that hexConvert was not as efficient as direct parsing of the paired hex
- removed cardPort.Write - this seems to echo the input...not sure why this was necessary...it seems to run fine w/o it and it speeds up the code quite a bit
private void _rfidCardDataReceived( object _cardPort, SerialDataReceivedEventArgs unused ){ // Do nothing if the reader is not supposed to be running. if ( !_readerRunning ) return; // Capture the port that the data was received on. SerialPort cardPort = (SerialPort) _cardPort; // Buffers for incoming card data. byte[] rawData = new byte[16]; // Incoming raw bytes from the serial connection. RfidEventArgs args = new RfidEventArgs(); string cardID = String.Empty; int bytesToRead = cardPort.BytesToRead; if ( bytesToRead == 16 ) { cardPort.Read( rawData, 0, rawData.Length ); int[] chk = new int[6]; chk[0] = HexAsciiToInt( rawData, 1 ); chk[1] = HexAsciiToInt( rawData, 3 ); chk[2] = HexAsciiToInt( rawData, 5 ); chk[3] = HexAsciiToInt( rawData, 7 ); chk[4] = HexAsciiToInt( rawData, 9 ); chk[5] = HexAsciiToInt( rawData, 11 ); if ( ( chk[0] ^ chk[1] ^ chk[2] ^ chk[3] ^ chk[4] ) == chk[5] ) { args.Success = true; args.RFID = ( ( ( chk[1] << 8 | chk[2] ) << 8 | chk[3] ) << 8 | chk[4] ); OnRfidEvent( args ); } else { args.Success = false; args.ErrorMsg = "Checksum mismatch on RFID: " + ( chk[0] ^ chk[1] ^ chk[2] ^ chk[3] ^ chk[4] ) + " vs " + chk[5]; OnRfidEvent( args ); } } else if ( bytesToRead > 16 ) // bytesToRead exceeds 16 (ie: too many cards read at same time, nuke everything) { // clear buffer cardPort.DiscardInBuffer(); args.Success = false; args.ErrorMsg = "Serial port buffer exceeds 16 bytes: " + bytesToRead; OnRfidEvent( args ); }}public int HexAsciiToInt( byte[] data, int offset, int length = 2 ){ int ret = 0; for ( int i = 0; i < length; i++ ) { ret = ret * (int) System.Math.Pow( 16, i ); // each digit is another power of 16 if ( data[offset + i] >= 48 && data[offset + i] <= 57 ) // number ret += data[offset + i] - 48; else // letter A - F ret += data[offset + i] - 55; } return ret;}
The full RFIDReader.cs...usage is similar to program code posted earlier in the thread except the class is renamed:
RFIDReader.cs 4.28KB 9 downloads
- Netduino Forums
- → Viewing Profile: Posts: buzz
- Privacy Policy