Pages: 1 2 [3]   Go Down
Author Topic: Using the RDM630 RFID Tag Reader and NewSoftwareSerial library  (Read 3526 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25732
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My problem was that I was taught BASIC at school - the old-fashioned version that required line numbers and pretty much only had for loops and GOTOs and GOSUBs as control structures.
Took me a while to get out of the habit when I learned ALGOL.
Glad I kicked it though.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
char CoolThings[] = "Vegemite", "Swimming", "Arduino";
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My problem was that I was taught BASIC at school - the old-fashioned version that required line numbers and pretty much only had for loops and GOTOs and GOSUBs as control structures.
Took me a while to get out of the habit when I learned ALGOL.
Glad I kicked it though.

I just started a computer technology class, and lucky for me, BASIC has come a long way in the past couple of years, so I probably (more like hopefully) won't have that problem.  And know that I know, I should be able to, even if I still 'need' to use gotos, I should be able to shake off the habit and keep it away smiley-razz
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

My first language was Minitran, a variant of Fortran. Early versions of that used line numbers, which you did GOTO.

Can't say I miss it. Like AWOL, I moved onto a structured language (NEAT/3 rather than ALGOL) and haven't used them since (unless writing assembler perhaps, which doesn't happen very often).
Logged

Warsaw, Poland
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino Lover.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
Here is the code (pro publico bono) which takes into account the official frame format from the sensor. We are synchronizing with the frame. We do not rely on the fact that every 13 characters there should be a new card number. Enjoy. Code should compile on Arduino Mega, for other Arduinos you have to replace Serial1 with instance of SoftwareSerial class (2 places in the code below). It works both with software and hardware UART.

Code:
void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);  // you can use softwareserial instead
}
unsigned char card[20];

// let's use the data frame format from RDM630 specification to avoid mismatch
// [0x02] [ 10 ASCII CHARACTERS ] [CHECKSUM] [0x03]

void loop()
{
  static unsigned char i=0;

  while(Serial1.available())
  {
    char c= Serial1.read();
    if(i==0)
    {
      //we are waiting for the first character of the next RFID tag. It has to be byte of value 2.
      //we ignore everything before we get 2.
      if(c==2)
      {
        card[i]=c;
        i++;
      }
    }
    else
    {
      //we are already into reading the ID so we do not ignore any more characters ...
      card[i]=c;
      i++;
      if((i>18) || (c==3))  // if we get a terminating byte (value=03 according to RDM630Reader specification)...
      {                            // ...or we are nearly buffer overflow for some reason
        decode();
        i=0;
      }
    }
  }
}

void decode()
{
  unsigned char p;
  //you  can add checksum calculation here to verify if the tag is correct
  // CHECKSUM: card 10byte DATA entire do XOR operation

  for(p=0;p<19;p++) // let's print the whole buffer however the tag ID itself is from card[1]  through[11]
  {
    Serial.print(card[p],HEX);
    Serial.print(" ");
  }
  Serial.println();
}


Moderator edit: quote tags removed, code tags added.
« Last Edit: November 01, 2012, 02:57:46 am by AWOL » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm guessing that what you posted doesn't look anything like what is stored on your computer, because you posted it wrong. Code tags (use the # icon), not quote tags.

Mangling code during posting doesn't help anyone.
Logged

Finland
Offline Offline
Sr. Member
****
Karma: 1
Posts: 270
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't want to start a flame war here, but there are some rare occasions where using gotos is justified (OP's example was obviously not one of those). I have sometimes used gotos as a kind of a exception throwing mechanism where it makes handing error conditions  simpler. Something like:

Code:
int foo()
{
    int ret;
    if (!(ret = do_something())) goto err;
    
    ...

    if (!(ret = do_something_else())) goto err;
    if (!(ret = do_something_more())) goto err;

    return OK;

  err:
    rollback();
    show_error_message();
    return ERR;
}


« Last Edit: November 01, 2012, 10:05:04 am by pekkaa » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That was what try/throw/catch was added for in recent times. Not supported under the compile options used by the IDE however.
Logged

Finland
Offline Offline
Sr. Member
****
Karma: 1
Posts: 270
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tend to use goto exception throwing in languages that don't support actual try/catch/throw mechanism, such as in Perl and vanilla C. I have to say that try/catch/throw exception handling is not any of my favorite features. It is especially irritating in Java, which forces to catch exceptions is cases where I would rather just let the program crash.
Logged

Pages: 1 2 [3]   Go Up
Jump to: