Go Down

Topic: Using the RDM630 RFID Tag Reader and NewSoftwareSerial library (Read 4517 times) previous topic - next topic

AWOL

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.
"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.

Koop


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 :P

Nick Gammon

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).
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

damago1

#33
Oct 31, 2012, 11:59 pm Last Edit: Nov 01, 2012, 08:57 am by AWOL Reason: 1
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: [Select]

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.

PaulS

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.

pekkaa

#35
Nov 01, 2012, 04:03 pm Last Edit: Nov 01, 2012, 04:05 pm by pekkaa Reason: 1
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: [Select]

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;
}




Nick Gammon

That was what try/throw/catch was added for in recent times. Not supported under the compile options used by the IDE however.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

pekkaa

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.

Go Up