Shop OBEX P1 Docs P2 Docs Learn Events
Javelin Serial Read using UART — Parallax Forums

Javelin Serial Read using UART

4ish4ish Posts: 24
edited 2005-10-18 11:48 in General Discussion
Hey guys,

I'm running into a problem trying to read from the RFID Reader (parallax). The code available for the reader is written in PBasic for the Basic Stamps, but I didnt think it would be a problem convverting it to Java.

Here's the basic code that supposedly works (havent tested it, but its in the manual so I figured it works)

RX PIN 4
T2400 CON 396
SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR buf\10]

and this is how I am doing it in Java

 final static int RX_PIN = CPU.pin7;
 
 static Uart rxUart = new Uart(Uart.dirReceive, RX_PIN, Uart.dontInvert,
                                 Uart.speed2400,Uart.stop1);
 public static void main(){
 if(rxUart.byteAvailable()){
        System.out.println("here1");
        c = (char)rxUart.receiveByte();
        buffer.append(c);
 }

this code is also from the javelin manual, so it should work, the only thing is the parameters I'm using for the Uart object I'm creating.

According to the RFID Readers·documents it says



Pin SOUT function: Serial Out. TTL-level interface, 2400bps, 8 data bits, no parity, 1 stop bit, true.

I dont know what the true means, but the rest of it should be the same as I've put in the code. No?

Anyway, here are some links to the documents I am talking about. Any help/suggestions would be greatly appreciated.



Doc Links:

RFID Reader: http://www.parallax.com/dl/docs/prod/audiovis/RFID-Reader-v1.1.pdf· (page 2)

Reader Basic Stamp Code: http://www.parallax.com/dl/src/prod/RFID1.BS2

Javelin Stamp Manual (section about Uart):
http://www.parallax.com/dl/docs/prod/javelin/JavelinStampMan1-0.pdf

Thanks alot.

·

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-10-15 01:17
    static int index =0;
    static boolean start = false;
    public static void main(){ · while (true) { //wait for multiple bytes to receive
    ··· if (rxUart.byteAvailable()) {
    ····· c = (char)rxUart.receiveByte();
    ····· if (!start) {
    ······· if (c == '\n') start = true; //WAIT($0A)
    ······}
    ····· else {
    ······· buffer.append(c); //STR buf\10
    ······· index++;
    ······· if (index == 10) {
    ········· for (int j=0; j<10; j++) {
    ··········· System.out.print(buffer.charAt(j)); //print received bytes
    ········· }
    ········· System.out.print('\n'); //print newline
    ········· index =0; //reset buf index
    ········· start = false; //wait for $0A again
    ······· }
    ····· }
    ··· }
    · }
    }

    regards peter
  • 4ish4ish Posts: 24
    edited 2005-10-16 07:39
    thanks for replying peter. I havent tried out the code yet, but if I am going to be the same object rxUart as I declared it, the byteAvailable will never be true. As you can see in my code I have a debug print statement inside that if clause and it never executes. perhaps I'm doing something wrong with the object declaration?
  • 4ish4ish Posts: 24
    edited 2005-10-17 21:18
    ok I guess I was wrong, I tried your code peter and it works great, but now I have another question. I ordered two different tags from parallax, but according to my program they have the same ID. Could this be the case?

    Thanks again.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-10-18 11:48
    From what I read on the parallax site, each ID is different.

    Which ID's did you read with your javelin program?

    regards peter
Sign In or Register to comment.