Shop OBEX P1 Docs P2 Docs Learn Events
reading from an RFID reader — Parallax Forums

reading from an RFID reader

coolbebecoolbebe Posts: 9
edited 2006-02-15 21:44 in General Discussion
I'm having some problems reading from the RFID reader.The output i get seems like i'm reading nothing.·Is there a way to test the reader? here is·the code i used.Any help or comments·will be appreciated.
Thanks

··· static int index = 0;
··· static boolean start = false;
··· final static int rxPin = CPU.pin1; // Pin for serial from reader

··· static Uart rxUart = new Uart(Uart.dirReceive, rxPin, Uart.dontInvert,
·································· Uart.speed2400, Uart.stop1);

··· static StringBuffer buffer = new StringBuffer(128);
··· static char c;
··· static String str = null;

· public static void main(){

····· System.out.println("Hello Bushra");
····· System.out.println(rxUart.byteAvailable());
····· try
····· {
·········· while(true)
·········· {
·············· if((CPU.readPin(CPU.pin1) == true) )
·············· {
················· if(rxUart.byteAvailable())
················· {
···················· c=(char)rxUart.receiveByte();
···················· if(!start)
···················· {
······················ if(c=='\n') start=true;
···················· }
················· }
················· else
················· {
··················· buffer.append(c);
··················· index++;
··················· if(index==10)
··················· {
····················· for(int i=0;i<10;i++)
····················· {
······················· System.out.print(buffer.charAt(i));
····················· }
··················· }
··················· System.out.print ('\n');
··················· index=0;
··················· start=false;
················· }

·············· }
·············· else
·············· {
··············· System.out.println("Cant read from pin");
·············· }
··········· }
······· }
······· catch(Exception e)
······· {
··········· System.out.println(e.getMessage());
······· }
······ }

Comments

  • John R.John R. Posts: 1,376
    edited 2006-02-15 18:26
    I can't help with the Javlin code, but you can test/debug the reader easily if you have a ttl leve serial LCD. You can supply 5 volts and ground to the LCD and Reader, set the LCD up for 2400 and connect the RFID reader to the LCD. The tag numbers should get dumped to the LCD.

    You could also get the same thing to hyperterm if you have something like a Pro Development Board where you could connect the serial out of the RFID reader to a UART with line drivers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.

    8 + 8 = 10
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-02-15 18:45
    You don't need to test the pin used by the uart

    ··· static int index = 0;
    ··· static boolean start = false;
    ··· final static int rxPin = CPU.pin1; // Pin for serial from reader

    ··· static Uart rxUart = new Uart(Uart.dirReceive, rxPin, Uart.dontInvert,
    ·································· Uart.speed2400, Uart.stop1);

    ··· static StringBuffer buffer = new StringBuffer(128);
    ··· static char c;
    ··· static String str = null;

    · public static void main() {

    ··· System.out.println("Hello Bushra");
    ····while(true)· {
    ·······try· {
    ·········if (rxUart.byteAvailable())· {
    ············c=(char)rxUart.receiveByte();
    ············if (!start)· {
    ··············if (c=='\n') start=true;
    ············}
    ·········}
    ·········else· {
    ···········buffer.append(c);
    ···········index++;
    ···········if (index==10)· {
    ·············for (int i=0;i<10;i++) {
    ···············System.out.print(buffer.charAt(i));
    ·············}
    ···········}
    ···········System.out.print ('\n');
    ···········index=0;
    ···········start=false;
    ·········}
    ······ }
    ······ catch(Exception e) {
    ··········· System.out.println(e.getMessage());
    ·······}
    ····}
    · }

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-02-15 18:58
    I guess you try to catch 10 bytes after \n from reader and display them.

    ··· static int index = 0;
    ··· static boolean start = false;
    ··· final static int rxPin = CPU.pin1; // Pin for serial from reader

    ··· static Uart rxUart = new Uart(Uart.dirReceive, rxPin, Uart.dontInvert,
    ·································· Uart.speed2400, Uart.stop1);

    ··· static StringBuffer buffer = new StringBuffer(128);
    ··· static char c;
    ··· static String str = null;

    · public static void main() {
    ·· System.out.println("Hello Bushra");
    ·· while(true) { //loop forever
    ····· //wait for '\n'
    ····· while(true)· {
    ·········if (rxUart.byteAvailable())· {
    ············c=(char)rxUart.receiveByte();
    ············if (c=='\n') break;
    ·········}
    ····· }
    ······//read 10 bytes and display
    ····· index=0;
    ····· while (index<10) {
    ······· if (rxUart.byteAvailable())·{
    ···········c = (char)rxUart.receiveByte();
    ···········System.out.print(c);
    ···········index++;
    ······· }
    ····· }
    ····· System.out.print('\n');
    ···} //end loop forever
    }

    regards peter
  • coolbebecoolbebe Posts: 9
    edited 2006-02-15 21:44
    Thank you guys for the quick response...i will use the LCD to try my reader·and try the code again.
    Thanks
Sign In or Register to comment.