reading from an RFID reader
coolbebe
Posts: 9
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());
······· }
······ }
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
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
··· 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
··· 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
Thanks