Pages: [1]   Go Down
Author Topic: Reading 35 ascii characters from card reader track  (Read 985 times)
0 Members and 1 Guest are viewing this topic.
Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello there. What could be the best approach to read large amount of ASCII data from a track in a card?.
I have a serial card reader (ID Tech IDMB) and data contained in the three tracks of a card in the standard format: %ABCD.........? and ;ABCD............?. My initial interest is to know the best approach to read a maximum of 35 ASCII characters from one track using my Arduino uno. For example:
%FIELD1 FIELD2 FIELD3 FIELD4 FIELD5?. I did this in the past but reading a maximum of 3 and 4 ascii characters and saving them in one variable. What I need to do now is to read a maximum of 35 ASCII character from one track. Should I create an ascii table? How to save them? I will appreciate any help. Thank you.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A char array is the most obvious way to store them. I suggest you keep the array null-terminated, so remember to size the array to include the final terminating char.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3384
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just posted this in another thread:


What you need is an array of chars:

Code:
const int maxLength = 50;
char readString[maxLength];

You also need an index variable (either global or static) that will keep track of where in the array you are.

Code:
int strIndex = 0;

And lastly, you need a character that will signal that you are done transmitting your string. This will depend on what program is sending you the string. The Arduino's Serial Monitor, for example can append '\r' and/or '\n' to the end of each transmission.

Code:
#define END_OF_STRING '\n'

From there you just need to read a character as you receive it and decide whether to parse the data and reset the array (if it's the END_OF_STRING marker):

Code:
// Do Something with the string
readString[0] = '\0'; // clear the array
strIndex = 0; // reset the index to 0

or add it to the array:

Code:
readString[strIndex] = inChar; // put the new char in the array
strIndex++; // increment our index for the next char
readString[strIndex] = '\0'; // null terminate our array to make it a proper string
Logged

Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you PeterH and Arrch.
Arrch, I will check your post and start to build the code and post here if I run into issues.
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9637
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do the strings sent start with either a "%" or ";" and always end with a "?" ?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It's a standard format B called sentinel.
For track 1: Start sentinel = %
             End sentinel = ?

For track 2: Start sentinel = ;
             End sentinel = ?

Track 3 is virtually unused by the major worldwide networks.

For a better understanding read http://en.wikipedia.org/wiki/Magnetic_stripe_card or google magnetic stripe card sources.
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9637
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code posted by others that captures the string between < and >. You could change that to % and ?.

Code:
String cmd;
String fullCmd;
boolean cmdComplete=false;

void setup () {
  Serial.begin(9600);
 cmd="";
 Serial.println("start duel delimit");
 }

void loop() {
  char c;
  while(Serial.available()) {
    c=Serial.read();
    if (c=='<') {
      cmd="";
    } else if (c=='>') {
      fullCmd=cmd;
      cmd="";
      cmdComplete=true;
      break;
    } else {
       cmd+=c;
    }
  }
  if (cmdComplete==true) {
    Serial.println('<' + fullCmd + "_OK>");
    cmdComplete=false;
  }
}
 
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks zoomkat for the code. I really didn't have issues to capture few characters. My challenge is to capture/save and use them for validation purposes. Initially I thought to use a bar code reader sample but the one provided by Arrch looks like a good approach.
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9637
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

lots of ways to parse captured strings to extract the desired data

http://arduino.cc/en/Tutorial/StringIndexOf

http://arduino.cc/en/Reference/StringObject
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Pages: [1]   Go Up
Jump to: